ambitious-aqua•15mo ago
Extract data from a json variable
I can't find out how to extract data from a variable on a page I'm crawling.
It looks like this:
My crawler is currently like this:
What am I doing wrong?
4 Replies
Are you trying to access the variable
jsondata
in the script
tag? I'm not sure that would be possible, or at least I have no experience with something like that and it isn't mentioned in the Playwright documentation.
Moreover, in this case, the variable is accessible only in the body of the callback passed to addEventListener
(inside the curly braces { }
) and it is not visible from outside, so I'm quite sure you cannot retrieve the data in this way.
But, apparently, the data is applied somehow to an element with ID wdresults
, so maybe you could use that element to scrape the data.Can't you just parse it from the page?
ambitious-aquaOP•15mo ago
I ended up doing it like this:
Not sure if that is the right way, but it works 🙂
There is no "right way" to do scraping, here you are essentially parsing the code text, which is a bit uncommon but works, so it shouldn't be a problem. 🙂