Curl FETCH Failure Consult

Source: Internet
Author: User
Ask a question, ha ~
Use Curl to crawl the data on this page ~ Ask the method
Http://mybus.xiamentd.com/LineDetailQuery?lineId=118&direction=1
Thx!


Reply to discussion (solution)

Adjust your program based on the return head

$url = ' http://mybus.xiamentd.com/LineDetailQuery?lineId=118&direction=1 ';p rint_r (get_headers ($url));
Array ([0] = http/1.1 302 Moved temporarily [1] = = Server:nginx [2] = Date:tue, 2013 12:00:53 GMT [3] = content-length:0 [4] = connection:close [5] = set-cookie:jsessionid=8852c73a784f0b95c9d e7fb33812eda0; path=/[6] = P3p:cp=cao PSA our [7] = set-cookie:httponly=true [8] = set-cookie:callbackurl=http%3 a%2f%2fmybus.xiamentd.com%2flinedetailquery%3flineid%3d118%26direction%3d1%26random%3d1386072053450; path=/[9] = location:http://xiamentd.com/getphoneinfo2.do?code= ahr0cdovl215ynvzlnhpyw1lbnrklmnvbs9maw5lrgv0ywlsuxvlcnk= [Ten] = http/1.1 302 Moved temporarily [one] = Server : Nginx [[] = Date:tue, 12:00:53 GMT [] = Content-type:text/html;charset=utf-8 [] =&gt ; content-length:0 [] = connection:close [+] = SET-COOKIE:WCITY_XM=4F706AE207628F6A3DE165FA08BE9E20; path=/; HttpOnly [+] = Location:http://mybus.xiamentd.com/linedetailquerY?return=2&tel=null&model=null [+] = http/1.1 302 Moved temporarily [+] = Server:nginx [20] =& Gt Date:tue, 12:00:53 GMT [+] = content-length:0 [] = connection:close [] = Set-cook ie:jsessionid=09c8413da570c390ed8f9f1346c1d78e; path=/[[] = P3p:cp=cao PSA Our [] + set-cookie:httponly=true [] = Set-cookie:callbackurl=htt p%3a%2f%2fmybus.xiamentd.com%2flinedetailquery%3freturn%3d2%26tel%3dnull%26model%3dnull%26random% 3d1386072053965; path=/[+] = location:http://xiamentd.com/getphoneinfo2.do?code= ahr0cdovl215ynvzlnhpyw1lbnrklmnvbs9maw5lrgv0ywlsuxvlcnk= [] = http/1.1 302 Moved temporarily [+] = Server : nginx [+] = date:tue, 12:00:54 GMT [+] = content-type:text/html;charset=utf-8 [+] =&gt ; content-length:0 [] = connection:close [] = set-cookie:wcity_xm=e1c22fc11a9dc09587b66d224257d91c; path=/; HttpOnly [] => Location:http://mybus.xiamentd.com/linedetailquery?return=2&tel=null&model=null [+] = HTTP/1.1 302 Moved temporarily [Panax notoginseng] = Server:nginx [+] = date:tue, Dec 12:00:54 GMT [+] = Content-leng th:0 [+] = connection:close [+] = set-cookie:jsessionid=b3034c324c287382ded4ef07d81ca04f; path=/[[] = P3p:cp=cao PSA Our [] [] = set-cookie:httponly=true [] = Set-cookie:callbackurl=htt p%3a%2f%2fmybus.xiamentd.com%2flinedetailquery%3freturn%3d2%26tel%3dnull%26model%3dnull%26random% 3d1386072054419; path=/[+] = location:http://xiamentd.com/getphoneinfo2.do?code= ahr0cdovl215ynvzlnhpyw1lbnrklmnvbs9maw5lrgv0ywlsuxvlcnk= [+] = http/1.1 302 Moved temporarily [+] = Server : Nginx [Date:tue]------12:00:54 GMT [+] = Content-type:text/html;charset=utf-8 [] =&gt ; content-length:0 [Wuyi] = connection:close [*] = set-cookie:wcity_xm=c38e38ff759c0707f5d45057227aa363; path=/; HttpOnly [54] [location:http://mybus.xiamentd.com/linedetailquery?return=2&tel=null&model=null]/= =& Gt  http/1.1 302 Moved temporarily [[+] = Server:nginx [+] = date:tue, Dec 12:00:54 GMT [+] = content-length:0 [+] = connection:close [n] = Set-cookie:jsessionid=cea724315de5284ba898b7bded29bab8; path=/[] = P3p:cp=cao PSA our [max] = set-cookie:httponly=true [+] = Set-cookie:callbackurl=htt p%3a%2f%2fmybus.xiamentd.com%2flinedetailquery%3freturn%3d2%26tel%3dnull%26model%3dnull%26random% 3d1386072054876; path=/[+] = location:http://xiamentd.com/getphoneinfo2.do?code= ahr0cdovl215ynvzlnhpyw1lbnrklmnvbs9maw5lrgv0ywlsuxvlcnk= [+] = http/1.1 302 Moved temporarily [+] = = Server : Nginx [Date:tue]----------12:00:55 GMT [+] = content-type:text/html;charset=utf-8 [=&gt] ; content-length:0 [] = Connection:Close [+] = SET-COOKIE:WCITY_XM=8A85502B900F458662118B57E5CEA9A5; path=/; HttpOnly [[+]] = location:http://mybus.xiamentd.com/linedetailquery?return=2&tel=null&model=null [72] =& Gt  http/1.1 302 Moved temporarily [[[]] = Server:nginx [about] = Date:tue, from Dec 12:00:55 GMT [] = content-length:0 [] = connection:close [+] = set-cookie:jsessionid=5be8764088155917f3f2eb96d785244e; path=/[+] = P3p:cp=cao PSA Our [] + set-cookie:httponly=true [+] = Set-cookie:callbackurl=htt p%3a%2f%2fmybus.xiamentd.com%2flinedetailquery%3freturn%3d2%26tel%3dnull%26model%3dnull%26random% 3d1386072055352; path=/[Bayi] = location:http://xiamentd.com/getphoneinfo2.do?code= ahr0cdovl215ynvzlnhpyw1lbnrklmnvbs9maw5lrgv0ywlsuxvlcnk= [[+] = http/1.1 302 Moved temporarily [the] + Server : nginx [+] = date:tue, 12:00:55 GMT [+] = content-type:text/html;charset=utf-8 [86] = [content-length:0] = connection:close [+] = set-cookie:wcity_xm=d152a1b50778e8c4b541694abfc67 b4f; path=/; HttpOnly [[+] = location:http://mybus.xiamentd.com/linedetailquery?return=2&tel=null&model=null [90] =& Gt  http/1.1 302 Moved temporarily [the] = Server:nginx [the] = Date:tue, the Dec 12:00:55 GMT [] = content-length:0 [94] = Connection:close [up] = set-cookie:jsessionid=7fb9c88b0499882cb2e6020ef71cd936; path=/[] = P3p:cp=cao PSA our [[] = set-cookie:httponly=true [98] = Set-cookie:callbackurl=htt p%3a%2f%2fmybus.xiamentd.com%2flinedetailquery%3freturn%3d2%26tel%3dnull%26model%3dnull%26random% 3d1386072055777; path=/[in] = location:http://xiamentd.com/getphoneinfo2.do?code= ahr0cdovl215ynvzlnhpyw1lbnrklmnvbs9maw5lrgv0ywlsuxvlcnk= [+] = http/1.1 302 Moved temporarily [101] = Serv    Er:nginx [102] = Date:tue, from Dec 12:00:56 GMT[103] = content-type:text/html;charset=utf-8 [104] = content-length:0 [+] = Connection:close [10 6] = set-cookie:wcity_xm=14de39508ca07769cda8e7abc0a0e74c; path=/;  HttpOnly [107] = Location:http://mybus.xiamentd.com/linedetailquery?return=2&tel=null&model=null [108] = http/1.1 302 Moved temporarily [109] = Server:nginx [+] = date:tue, Dec 12:00:56 GMT [ 111] [content-length:0] = connection:close [113] = set-cookie:jsessionid=a32f3833adfdf773b3f097 a76efc682a; path=/[[+] = P3p:cp=cao PSA our [[+] = set-cookie:httponly=true [] = set-cookie:callbackurl= http%3a%2f%2fmybus.xiamentd.com%2flinedetailquery%3freturn%3d2%26tel%3dnull%26model%3dnull%26random% 3d1386072056242; path=/[117] = location:http://xiamentd.com/getphoneinfo2.do?code= ahr0cdovl215ynvzlnhpyw1lbnrklmnvbs9maw5lrgv0ywlsuxvlcnk= [118] = http/1.1 302 Moved temporarily [119] => Server:nginx [+] = date:tue, 12:00:56 GMT [121] = Content-type:text/html;charset=utf-8 [ 122] = content-length:0 [123] = Connection:close [124] = Set-cookie:wcity_xm=4016aba220428b15bfe4ad64 599830A9; path=/;  HttpOnly [126] [Location:http://mybus.xiamentd.com/linedetailquery?return=2&tel=null&model=null] = http/1.1 302 Moved temporarily [127] = Server:nginx [+] = date:tue, Dec 12:00:56 GMT [ 129] = content-length:0 [] = connection:close [131] = SET-COOKIE:JSESSIONID=65B7BF224ECE837BF5E1DD C9C170E3FE; path=/[[+] = P3p:cp=cao PSA our [133] = set-cookie:httponly=true [134] = Set-cookie:callbackurl= http%3a%2f%2fmybus.xiamentd.com%2flinedetailquery%3freturn%3d2%26tel%3dnull%26model%3dnull%26random% 3d1386072056735; path=/[135] = location:http://xiamentd.com/getphoneinfo2.do?code= Ahr0cdovl215ynvzlnhpyw1lbnrklmnvbs9maw5lrgv0ywlsuxvlcnk= [136] = http/1.1 302 Moved temporarily [137] = Server:nginx [138] = Date:tue, 201 3 12:00:57 GMT [139] = Content-type:text/html;charset=utf-8 [+] = content-length:0 [141] = Connec Tion:close [142] = set-cookie:wcity_xm=32f478e1b2f062fd1e6737996280a263; path=/;  HttpOnly [143] = Location:http://mybus.xiamentd.com/linedetailquery?return=2&tel=null&model=null [144] = http/1.1 302 Moved temporarily [145] = Server:nginx [146] = Date:tue, Dec 12:00:57 GMT [ 147] = content-length:0 [148] = connection:close [149] = set-cookie:jsessionid=e2dc3fbfc8af3db7ea9208 D13E3B9AB1; path=/[] = P3p:cp=cao PSA our [151] = set-cookie:httponly=true [all] = Set-cookie:callbackurl= http%3a%2f%2fmybus.xiamentd.com%2flinedetailquery%3freturn%3d2%26tel%3dnull%26model%3dnull%26random% 3d1386072057198; path=/[153] = location:http://xiamentd.com/getphoneinfo2.do?code=ahr0cdovl215ynvzlnhpyw1lbnrklmnvbs9maw5lrgv0ywlsuxvlcnk= [154] = HTTP/1.1 302 Moved temporarily [155] = Server:nginx [156] = Date:tue, Dec 12:00:57 GMT [157] = Content-type:t Ext/html;charset=utf-8 [158] = content-length:0 [159] = connection:close [] = Set-cookie:wcity_ xm=96ab72f98012abf5d1a396ef2259d203; path=/;  HttpOnly [161] = Location:http://mybus.xiamentd.com/linedetailquery?return=2&tel=null&model=null [162] = http/1.1 302 Moved temporarily [163] = Server:nginx .....

Adjust your program based on the return head

$url = ' http://mybus.xiamentd.com/LineDetailQuery?lineId=118&direction=1 ';p rint_r (get_headers ($url));
Array (    [0] = http/1.1 302 Moved temporarily    [1] = = Server:nginx    [2] = Date:tue, 2013 12:00 : content-length:0 GMT    [3] = = [    4] = Connection:close    [5] = set-cookie:jsessionid= 8852c73a784f0b95c9de7fb33812eda0; path=/.....


Page seems to stop 302 jump page crawl also no data

So you need to tweak your program.
If you have 302, you need to set curlopt_followlocation
If you have cookies, you need to set Curlopt_cookiejar and Curlopt_cookiefile

Can the living be suffocated by the urine?

So you need to tweak your program.
If you have 302, you need to set curlopt_followlocation
If you have cookies, you need to set Curlopt_cookiejar and Curlopt_cookiefile

Can the living be suffocated by the urine?
These two tried last night, but they couldn't.

$url = ' http://mybus.xiamentd.com/LineDetailQuery?lineId=118&direction=1 '; $cookie = Tempnam ('./', ' cookie '); $ch = Curl_init ($url); curl_setopt ($ch, curlopt_returntransfer,1); curl_setopt ($ch, Curlopt_cookiejar, $cookie); curl_ Setopt ($ch, curlopt_followlocation,1); curl_exec ($ch); Curl_close ($ch); $ch = Curl_init ($url); curl_setopt ($ch, curlopt_returntransfer,1); curl_setopt ($ch, Curlopt_cookiefile, $cookie); curl_setopt ($ch, curlopt_followlocation, 1 ); $content = Curl_exec ($ch); Echo $content; Empty
  • 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.