Web Crawler-how does phpcurl obtain the verification code session_id?

Source: Internet
Author: User
Try logging in with curl today and enter the verification code manually. Question and how can I use curl to simulate form login with image verification code? Similarly, my question is, how can I get a session or set a session when pulling an image? (The first answer to that question is not correct. Try logging in with curl today and enter the verification code manually.

Question and how can I use curl to simulate form login with image verification code? Similar

My question is, how can I get the session or set it when I pull the image?

(The first answer to that question is not correct)

Please help me.

Reply content:

Try logging in with curl today and enter the verification code manually.

Question and how can I use curl to simulate form login with image verification code? Similar

My question is, how can I get the session or set it when I pull the image?

(The first answer to that question is not correct)

Please help me.

$ Cookie_file = dirname (_ FILE __). '/cookies/'.w.user.'cookie.txt'; // initialize $ curl = curl_init ('HTTP: // '); $ header = array (); $ header [] = 'user-Agent: mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36 '; curl_setopt ($ curl, CURLOPT_HTTPHEADER, $ header ); // do not output the header information curl_setopt ($ curl, CURLOPT_HEADER, 0); // save it to a string instead of curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ curl, CURLOPT_COOKIEJAR, $ cookie_file); // store cookies // post Data curl_setopt ($ curl, CURLOPT_POST, 1); // request data curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ post ); // whether to capture the redirected page curl_setopt ($ curl, CURLOPT_FOLLOWLOCATION, 1); $ response = curl_exec ($ curl); curl_close ($ curl );

Get session

It is not generic. Don't say no

// Obtain the cookie value private function getCookies () {$ curl = curl_init ('HTTP: // 113.57.132.2: 83/login. aspx '); // do not output the header information curl_setopt ($ curl, CURLOPT_HEADER, 1); curl_setopt ($ curl, CURLOPT_NOBODY, 1); // disguise the browser curl_setopt ($ curl, CURLOPT_USERAGENT, 'mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/123 '); // save it to a string instead of outputting curl_setopt ($ curl, CURLOPT_RETURNTRANS FER, 1); $ rs = curl_exec ($ curl); curl_close ($ curl); preg_match ('% ASP. NET_SessionId = .*?; % Sim ', $ rs, $ arr); $ cookies = str_replace ('asp. NET_SessionId = ', '', $ arr [0]); $ cookies = rtrim ($ cookies,'; '); return $ cookies; // $ this-> $ cookies = rtrim ($ cookies ,';');}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.