In the web page crawled by CURL, other pages are referenced through the relative path. how does one solve the cookie problem? Curl relative path cookie
For example, if you use curl to capture page A, page A References page B through the relative path, Page B has the Set-Cookie header, and page A does not have Set-Cooike.
I can only capture page A through curl, but cannot catch the cookie because the cookie is set on page B. Ask experts to solve the problem! Thank you!
Reply to discussion (solution)
Captured twice/multiple times
In fact, ajax/verification code and so on are all done in this way.
Header ("Content-type: text/html; charset = utf-8"); function request_by_curl ($ remote_server, $ post_string) {$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ remote_server); curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_string); curl_setopt ($ ch, success, true); curl_setopt ($ ch, CURLOPT_NOBODY, false ); curl_setopt ($ ch, CURLOPT_HEADER, true); curl_setopt ($ ch, CURLOPT_HTTPHEADER, array (); $ data = curl_exec ($ ch); curl_close ($ ch ); return $ data;} // Obtain the verification code file_get_contents ("http://jysx.scnu.edu.cn/VerifyImg.aspx"); $ cookie = $ http_response_header [6]; $ code = substr ($ cookie, 23,4); echo $ code."
"; // Post login $ remote_server =" http://jysx.scnu.edu.cn/login.aspx "; $ post_string = 'act = login & type = ajax & name = 20102301025 & pass = 523523 & verify = '. $ code; echo request_by_curl ($ remote_server, $ post_string );
This is the php code that I simulated to log on to South China Normal University for an internship.
Yes !!!!!
Why does this website write the verification code to the header ??