4

I am looking for a way to access a website's window varibles through python how can I do this?

For example, I want to get the data from window.performance. How can I do that with python? Is it possible to use the requests library?

I have attached the image: I have attached the image

2
  • Your problem has nothing to do with Python or the Requests library. This question is about how to send a HTTP request that will cause the data you want to be returned from the site, and then parsing that data out of the response. Just about any HTTP client library in any language is probably going to facilitate that. I'm not a web guy, but I think you're talking about JavaScript functions that are referenced from Javascript running inside a web page. Making a HTTP request isn't going to ever give you access to this for a general web site. Rather, the site would have to publish that info. Commented Jun 12, 2019 at 2:25
  • ...unless you want to use Python to script the running of a web browser, cause it to load a page, and then query its API to have it look into the guts of the page and give you this information. My guess that you're not looking to go through all this work Commented Jun 12, 2019 at 2:30

2 Answers 2

1

Python requests doesn't have access to running JavaScript on the page, which is what you'll need to get metrics like that. Requests will only gather the raw HTML data (what you see when you view the page source), and it won't be able to gather the JavaScript window object.

To do such a thing like this, you'll need a headless browser, which has access to inline JavaScript on the website. Something like this might interest you.

Regardless, you should look into using a headless browser which would have access to the live rendered site. Something like Selenium, Nightmare, Puppeteer, etc. would be of good use in this instance.


Sign up to request clarification or add additional context in comments.

Comments

0

the case is retrieving data which web app stores in the window js object or global scope in browser. The workflow is programming or instructing a headless browser with corresponding API in your language. #programming##data retrieve##access the window object in browser#

Comments

Your Answer

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.