0

How do I get url that is hidden by javascript on external website?

ex: http://royaldesign.se/Att_Dricka.aspx This url is constant through navigation of pages, so page content is loaded by javascript.

link location of a page:

javascript:__doPostBack('ctl00$masterContent$DataPager2$ctl00$ctl00','')
javascript:__doPostBack('ctl00$masterContent$DataPager1$ctl00$ctl01','')
javascript:__doPostBack('ctl00$masterContent$DataPager1$ctl00$ctl02','')

.....

Is there a way to analyze (manually or by PHP script) the function __doPostBack to find out about the urls?

Thx in advance

Joe Doyle
  • 6,223
  • 3
  • 38
  • 44
Alex Mass
  • 1
  • 1
  • 1
  • 1
  • What would you do with it if you had it? In your example, the javascript is doing a post back, which is a "link" to the original page. – Seth Aug 20 '12 at 23:51
  • You might be interested in my answer to another question just now: http://stackoverflow.com/questions/12029324/curl-script-just-filling-up-the-form-not-submitting-it/12046718#12046718 – IMSoP Aug 20 '12 at 23:57
  • I need those urls in order to fetch the content of pages. I use file_get_contents from php. So the solution would be either get the urls or simulate the pagination using __doPostBack function. – Alex Mass Aug 21 '12 at 14:22

3 Answers3

0

Those values are not hidden, the __doPostBack method posts back to itself. Those values passed to doPostBack represent the html ID's of the control doing the postback.

The page your looking at is written in ASP.NET also, not PHP.

You can use your browsers debug tools to see what data is being passed back to the server via javascript.

databyss
  • 5,538
  • 1
  • 19
  • 23
  • Can I get content of pages in this way? The point is that I want to use file_get_contents to fetch the contents of the actual page. – Alex Mass Aug 21 '12 at 14:28
  • It's triggering the form and either reloading the page or loading that segment by javascript. You would have to look into using CURL to trigger the same form action. – databyss Aug 21 '12 at 18:53
  • Then there is no simpler way than Curl? Do you know of a good Curl tutorial describing this functionality? – Alex Mass Aug 21 '12 at 22:22
0

The __doPostBack javascript function is used to submit data to an asp.net page.

The first parameter to the function is the event target. This is the ClientID of the control that is being clicked.

Asp.net uses this value to raise a Click event on the server when the page gets submitted.

You can call this __doPostBack function via javascript yourself to get the same behavior as a user clicking it.

nunespascal
  • 17,118
  • 2
  • 37
  • 42
  • Could you give an example on how to do this? – Alex Mass Aug 21 '12 at 14:26
  • Open the URL that has those links in your browser. Then put this in your browser address bar `javascript:__doPostBack('ctl00$masterContent$DataPager2$ctl00$ctl00','')` and press enter, it will work just like the button in concern has been pressed. There are browser plugins like greasemonkey that can be used to automatically call such scripts. – nunespascal Aug 21 '12 at 18:38
  • I opened the url http://royaldesign.se/Att_Dricka.aspx and then paste javascript:__doPostBack('ctl00$masterContent$DataPager1$ctl00$ctl02','') to go to page 3, but without any result!! – Alex Mass Aug 21 '12 at 22:12
0

I gave some tips on "scraping" ASP.net pages on this other question: curl script just filling up the form not submitting it

The basics of simulating a POST request using CURL are discussed here: PHP + curl, HTTP POST sample code?

I would also add that if the site you are "scraping" from is owned by someone you are on friendly terms with (and not e.g. a competitor!) you may be able to save a lot of time by asking nicely for the content, or a static URL that gives you the content.

Community
  • 1
  • 1
IMSoP
  • 65,743
  • 7
  • 83
  • 127
  • Is it possible to use phantomjs (http://phantomjs.org/) to get the content loaded by javascript? – Alex Mass Aug 25 '12 at 05:42
  • You could certainly try. Note that it's not just the Javascript you've got to run/simulate, but the user interaction itself - the __doPostBack method, for instance, will probably need to be fired in the context of a click event on the submit button, not just as a context-free function. – IMSoP Aug 25 '12 at 12:02