0

I have a website that I want to scrape data from. This specific data is under a script tag and I cannot figure out how to access it.

<script type="text/javascript">
 window.gameData = {"a dict of data I would like to get"}
</script>

So far I have tried probably every combination of "find_element_by..." and I am beginning to wonder if this problem can even be solved. It doesn't allow me to use the "get_attribute", ".text", or any other helpful selenium function.

I even tried this function

#script = wd.find_element_by_xpath('//*[@id="js-hook-pz-moment__game"]/script/text()')

Which is the direct xpath to the javascript loaded data and it returned a quite scary error.

selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: The result of the xpath expression "//*[@id="js-hook-pz-moment__game"]/script/text()" is: [object Text]. It should be an element.

So thats my problem. Thank you for any and all help :)

asked Feb 24, 2022 at 0:05

1 Answer 1

1

You would just do:

game_data = driver.execute_script("return window.gameData")
answered Feb 24, 2022 at 1:25
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.