(soup, filter)
| 224 | |
| 225 | |
| 226 | def extract_ld_json(soup, filter): |
| 227 | ld_json_tags = soup.find_all("script", type="application/ld+json") |
| 228 | |
| 229 | results = [] |
| 230 | for tag in ld_json_tags: |
| 231 | try: |
| 232 | ld_json = json.loads(tag.string) |
| 233 | if filter is None: |
| 234 | results.append(ld_json) |
| 235 | elif isinstance(filter, str) and filter in ld_json: |
| 236 | results.append(ld_json) |
| 237 | elif ( |
| 238 | hasattr(filter, "__iter__") |
| 239 | and len(filter) == 2 |
| 240 | and filter[0] in ld_json |
| 241 | and ld_json[filter[0]] == filter[1] |
| 242 | ): |
| 243 | results.append(ld_json) |
| 244 | elif callable(filter) and filter(ld_json): |
| 245 | results.append(ld_json) |
| 246 | except json.JSONDecodeError: |
| 247 | continue |
| 248 | |
| 249 | return results |
| 250 | |
| 251 | |
| 252 | def extract_meta_content(soup, property_name): |
nothing calls this directly
no outgoing calls
no test coverage detected