To extract some data from google's search, we found that google was very blocked from the software's data capture. Previously, we forged the USER-AGENT to capture data, but now it is not working. Using packet capture data, we found that Google judges cookies. If you do not have any cookies, you will directly return a 302 jump, and dozens of 302 jumps in a row will not be able to grasp the data.
Therefore, when sending a search command, you need to extract and save the cookies, and then use the saved cookies to send the search command again to capture data normally. This is actually the same as the simulated login on the Forum. First, POST the login, obtain the cookies and save them, and then use the cookies to access them.
1. Define the Cookie storage path
Absolute path is required
$cookie_jar = dirname(__FILE__)."/pic.cookie";
Ii. obtain cookies
Store cookies into files
$url = "http://1.2.3.4/";$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);$content = curl_exec($ch);curl_close($ch);
3. simulate a browser to obtain the verification code
The server verification code has a vulnerability and can be specified by yourself.
Extract the cookie and submit it to the server so that the server can open the login page as a browser.
$ch = curl_init();curl_setopt($ch, CURLOPT_URL, 'http://1.2.3.4/getCheckpic.action?rand=6836.185874812305');curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);$ret = curl_exec($ch);curl_close($ch);
Iv. POST submission
$post = "name=2&userType=1&passwd=asdf&loginType=1&rand=6836&imageField.x=25&imageField.y=7"; $ch = curl_init();curl_setopt($ch, CURLOPT_URL, "http://1.2.3.4/loginstudent.action");curl_setopt($ch, CURLOPT_HEADER, false);curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);curl_setopt($ch, CURLOPT_POSTFIELDS, $post);curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);$result=curl_exec($ch);curl_close($ch);
5. Get data on the specified page
$ch = curl_init();curl_setopt($ch, CURLOPT_URL, "http://1.2.3.4/accountcardUser.action");curl_setopt($ch, CURLOPT_HEADER, false);curl_setopt($ch, CURLOPT_HEADER, 0);curl_setopt($ch, CURLOPT_RETURNTRANSFER,0); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_jar);$html=curl_exec($ch);// var_dump($html);curl_close($ch);