Python requests: post JavaScript commands

Question:

I’m trying to get the content of a site, but this content only appears when I click the ‘Chart’ link, which is a JavaScript command like this:

javascript:__doPostBack('fcc1$dgrC$ctl02$ctl00',''

from a element like this:

<a href="javascript:__doPostBack(&#39;fcc1$dgrC$ctl02$ctl00&#39;,&#39;&#39;)">Chart</a>

This is the site:
enter image description here

And this is what happens when you click on ‘Chart’:
enter image description here

You can see that the link doesn’t change, so the only way to get the chart code is by somehow send that JavaScript command

How to find all the chart links?
How can I do a ‘virtual click’ on the chart links?
And after that, how to get the new html?

I really appreciate your help!

Asked By: Mr.Iago

||

Answers:

If those links are indeed “clicked” by javascript listeners, you may have trouble finding a real link to click.

Instead, you could use a tool to simulate a web browser in python and “click” on that link to get to the next page. The best one I’ve used is Mechanical Soup: https://mechanicalsoup.readthedocs.io/en/stable/introduction.html.

Answered By: Vikas Yendluri

doPostBack just sets the __EVENTTARGET and __EVENTARGUMENT form fields and submits the form. Those '’s are just quotes BTW.

Answered By: pguardiario