Search code examples
phpweb-scrapingdom

PHP scraping thwarted by redirects


I am trying to convert a library search engine to a mobile friendly site in a php script. The plan is to scrape the results and present a simplified form, as the site only looks good in a large browser at the moment.

I am having a little trouble using http://simplehtmldom.sourceforge.net because everytime I try to load a query by loading this page www.librarywebsite.com/search.php?query=BOOKTITLE it goes through several redirects and then presents a final results page which has a similar set of parameters in the url but which, if refreshed, insists on the redirect anyway.

Does anyone know how to perform a DOM scrape only after all redirects have been completed?


Solution

  • You may consider using something like cURL with follow redirects enabled. I believe the cURL option is CURLOPT_FOLLOWLOCATION. See: http://php.net/manual/en/function.curl-setopt.php