Python crawls Ctrip plane flight information

Source: Internet
Author: User

Yesterday to interview the interviewer gave a question let me crawl a website information thought: It's so simple small case but open Ctrip station crawl

No flight information was found ... Has reopened Ctrip's website A look I wipe the data incredibly is asynchronously loaded this time some play
Open the console to see the information. There was no flight data at the beginning.

See this request address returned information something like flight data
Try using Python to request a look at the data format

Import urllib.request
import json
url = ' http://flights.ctrip.com/domesticsearch/search/ Searchfirstrouteflights? dcity1=sha&acity1=bjs&searchtype=s&ddate1=2017-10-22&isnearairportrecommond=0&logtoken= D5c2cdde121640c587b2737a160555cc&rk=6.87741369292242094159&ck=b4828167808be5de87c5814b02c113a3&r= 0.44130167627926424060312 '
headers = {'
    Host ': ' flights.ctrip.com ',
    ' user-agent ': ' mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) gecko/20100101 firefox/56.0 ","
    Referer ":" Http://flights.ctrip.com/booking/SHA-BJS-day-1.html? Ddate1=2017-10-22 ",
    " Connection ":" Keep-alive ",
}
res = urllib.request.Request (url,headers=headers)
res = Urllib.request.urlopen (res). Read (). Decode ("gb2312")
Jsondata = json.loads (res)
print (res)
From the above request, we see that the returned data is encoded as gb2312. We saw the information here. It's really flight information .

See the flight information data in the FIS this array we'll loop around to see if the flight information is correct I took to compare the information is correct finally excited to pay the project offer finally or not get the technology too much to ask Daniel with Q code 823688826 Small white to communicate AH

Related Article

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.