MCPcopy Create free account
hub / github.com/omkarcloud/botasaurus / extract_ld_json

Function extract_ld_json

botasaurus/cl.py:226–249  ·  view source on GitHub ↗
(soup, filter)

Source from the content-addressed store, hash-verified

224
225
226def 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
252def extract_meta_content(soup, property_name):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected