Is it possible to retrieve source code of a redirected web page that uses sessions and cookies with PHP?
-
There is a web page that I want to scrape some elements from but theĀ page requires the viewer to click a link to get to the page. The url is like this: http://exampledomain.com/gp/bestsellers/books/10578201/375-9114798-0670610 If I access that page, it displays a link to confirm the visitors age to check if the visitor is matured enough to view the contents. The link url is like this: http://exampledomain.com/gp/product/black-curtain-redirect.html?redirectUrl=%2Fgp%2Fbestsellers%2Fbooks%2F10578201 If the link is clicked, it redirects back to the original page and the actual contents are shown, http://exampledomain.com/gp/bestsellers/books/10578201/378-5247603-7740217?&redirect=true I'm guessing that the server uses sessions and cookies or referrer to decide whether it redirects to the destination page. So is it possible to retrieve the source code of such a page?
-
Answer:
I'm not 100% sure that I understand the question, but I'll try to answer... In short, yes. You will probably need to use cURL or something similar though. Please see the bottom answer here: http://stackoverflow.com/questions/3519939/make-curl-follow-redirects
Marty Gottesfeld at Quora Visit the source
Other answers
Yes it is possible, you just need to track the cookies that the server sets in the age verification form, and add them to the request headers of the following pages. google chrome will help you write your curl command, as you can copy any request sent from your browser as a curl command with all its headers attached already!see: http://stackoverflow.com/questions/15995919/curl-how-to-send-cookies-via-command-linehttp://www.lornajane.net/posts/2013/chrome-feature-copy-as-curl
Ahmad Moqanasa
You're going to have to use a browser.The way to do this is to use a library like Selenium or PhantomJS to open the first URL, click the redirect on the page and then get data programmatically.
Hugo Di Francesco
Related Q & A:
- How to translate a complete web page?Best solution by Server Fault
- How do i create a Yahoo web page?Best solution by iwebhostingplans.com
- In the simplest clearest language possible, can any one tell me step by step how to get a web page or domain?Best solution by Yahoo! Answers
- How can I block a specific web page?Best solution by Yahoo! Answers
- What is a good web page to apply for a job?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.