I have to download a page to parse some value in it. I would like to use PHP, it download the page, parse the data and return html with results. But i have to login before on the site to get the target page. How can i do it with php?
1 Answers
Best option is to follow the logon process when logging in manually using a browser like Google Chrome. You need to enable the network monitor. Press F12 to enable the developer tools, navigate to tab 'Network' and enable the checkmark at 'Preserve Log'. You can optionally select the disable cache checkmark.
Then clear all history and cookies so you're sure the site doesn't logon automatically.
No you're set to logon manually through the website. Type the site's URL for the login page and watch the items in the developer tools roll by. When your login is complete, head over to the top of the list of items in the network and look for a POST entry in the second column. This usually indicates the browser posting the logon information to the website.
Most sites respond using a 30x response and place a cookie. Now you now how the site operates. Have a look at my answer to a similar question: PHP curl login couldn't pass login page
and use the CURL library to first logon, receive the cookie and while keeping the connection open get the page after the login you need.