How does one execute a navigational link from a php script?
The href link contains the following in it's source href="javascript:__doPostBack('SearchResultsGrid$ctl29$ctl02',)"

I need to execute the javascript somehow to navigate to the next page.
Please advise in simple terms

    I'm confused; it doesn't sound like your issue directly relates to PHP. As such, I'm moving the thread to the ClientSide Technologies forum.

    The "javascript:" pseudo-protocol is generally considered a bad practice. Instead, use the "onclick" attribute of the <a> entity to call this __doPostBack() function.

    Other than that... you haven't told us what results you're getting versus what you expected. Does it work? Does your browser's JavaScript console emit any warning or error messages?

      My guess is (s)he's trying to scrape a site built in .NET because that's how it outputs all anchors... with an href using the javascript psuedo-protocol.

        Now that would make more sense in the context of a server-side script... and also serve to yet again reinforce the notion that screen-scraping is a Very Bad Solution (TM).

          As I said I'm a novice. I am doing what you call screen scraping. Is there a way to do the navigation from a php script.
          I was asked to extract data from a URL. If there is a better method of doing this, please be kind enough to share it.

          Thanks

            phpNovice12;11038887 wrote:

            Is there a way to do the navigation from a php script.

            Well, one way might be to use the [man]v8js[/man] extension to integrate JavaScript functionality into PHP. I've never tried (or even considered) this before, so I can't comment as to the complexity or effectiveness of such a solution. Personally, if you're talking about integrating JS with PHP, I'd say you're (probably) doing something wrong.

            Otherwise, you could examine this __doPostBack() function, determine what it would do in the user's browser, and replicate that behavior/code in your PHP script instead.

            phpNovice12;11038887 wrote:

            If there is a better method of doing this, please be kind enough to share it.

            The best way to do screen-scraping is: don't do it at all.

            What is your goal? If you're attempting to extract information from a 3rd-party site, look for an API instead. HTML pages are generally served for the benefit of a browser on a user's PC - not another web service (that's what APIs are for). If you can't find, perhaps try contacting the webmaster of that site and see if there are other options available to you.

              Finally if you really really have to do this via screen scraping, you had better check the ToC of the site to make sure you are not violating it.

              PHPBuilder Terms of Service wrote:

              You agree that you will not:
              Use any robot, spider, site search/retrieval application or other manual or automatic device to retrieve, index, "scrape," "data mine" or in any way gather Site content or reproduce or circumvent the navigational structure or presentation of the Site without our express prior written consent. Notwithstanding the immediately foregoing sentence (but subject to the other items listed above), we grant the operators of public search engines permission to use spiders to copy materials from the Site for the sole purpose of and solely to the extent necessary for creating publicly-available searchable indices of such materials, but not caches or archives of such materials. We reserve the right to revoke these exceptions, either generally or in specific cases, at any time.

              If you are indeed allowed to automagically scrape all the content, then I would suggest using javascript and a headless browser such as phantomjs.

                Depends on the site; many of these .NET sites will also accept params via GET.

                  Right dale, mostly they are just links, however .NET hides where it goes via the doPostBack which is totally useless and increases overhead (one of the reasons I'm so glad not to be working in .NET)

                    What I didn't like was VIEWSTATE et al ....

                      a year later

                      Incidentally, the PHP answer is pretty convoluted, but goes something like:

                      Set up cURL, GET the first page, parse the parameters to feed to the doPostBack function (EVENTARGUMENT, EVENTTARGET), record the other hidden vars (VIEWSTATE, VIEWSTATEGENERATOR, __EVENTVALIDATION), hand them to cURL as its POST array (CURLOPT_POSTFIELDS), and then let cURL download the data.

                      Messy, but can be done.

                        Write a Reply...