• 大小: 28.09MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-16
  • 语言: Python
  • 标签:

资源简介

基于Python的http流抓取系统 用于查询IP 用于查询火车票 用于查询飞机票 用于查询下载播放歌曲

资源截图

代码片段和文件信息

#coding=utf-8
import sys timereurllib2parsercookielibjsonurllib

‘‘‘Cookies‘‘‘
cookie=cookielib.LWPCookieJar()
chandle=urllib2.HTTPCookieProcessor(cookie)


‘‘‘获取数据‘‘‘
def getData(url):
    r=urllib2.Request(url)
    opener=urllib2.build_opener(chandle)
    u=opener.open(r)
    data=u.read()
    try:
        data=data.decode(‘utf-8‘)
    except:
        data=data.decode(‘gbk‘‘ignore‘)
    return data

def postData(urldata):
    data=urllib.urlencode(data)
    data=bytes(data‘utf-8‘)
    r=urllib2.Request(urldata)
    opener=urllib2.build_opener(chandle)
    u=opener.open(r)
    data=u.read()
    try:
        data=data.decode(‘utf-8‘)
    except:
        data=data.decode(‘gbk‘‘ignore‘)
    return data

‘‘‘获取城市的编码‘‘‘
def GetCityCode(offPort):    
    cont=getData(‘http://www.ly.com/Flight/FlightBookAjax.aspx?Type=GetAllCity&callback=tc68544171312‘)
    offPort=‘“‘+offPort+‘“‘
    cont= cont.split(‘hot‘)
    haveCode=‘‘
    for x in cont:
        if offPort in x:
            haveCode=x
            break
    fin= haveCode.split(‘‘)
    code=‘code‘
    for y in fin:
        if code in y:
            code=y
            break
    return code.split(‘:‘)[1][1:4]

‘‘‘获取飞机票信息‘‘‘
class AirPlane:
    def init(selfoffPortarrPortdate):
        self.li=[]
        offPort_code=GetCityCode(offPort)
        arrPort_code=GetCityCode(arrPort)
        url=‘http://www.ly.com/Flight/FlightBookAjax.aspx?Type=QryFlightInfoNew&sort=0&errinner=&TcA=11103084&FilterList=&CabinCode=all&FlightNum=&CompanyCode=all&domain=&plat=&key=B9706D48D6D54250A616559CF3620B26&IsRevisionAfter=fznew&querytype=0&fquerykey=db2ba81e-4260-4fac-b63d-cc93148c78d7&cztype=&IfVip=0&FqdLoginKey=1416582338507554&firstday=%s&isNew=1&offPort=%s&arrPort=%s&date=%s&queryParagraph=1&iid=0.23819635355976443‘ %(dateoffPort_codearrPort_codedate)
        cont= getData(url).split(‘“result“:“‘)[1]
        cont=cont.split(“|“)
        cont1=[]
        i=0
        while i             cont1.append(cont[i])
            i+=2
        i=0
        while i            tmp=[]
            tmp.append(cont1[i].split(‘‘)[3])#起飞时间
            tmp.append(cont1[i].split(‘‘)[5])#到达时间
            tmp.append(cont1[i].split(‘‘)[1]+cont1[i].split(‘‘)[2]) #航班
            tmp.append(cont1[i].split(‘‘)[7]+‘(‘+cont1[i].split(‘‘)[15]+‘)‘)#机型
            tmp.append(cont1[i].split(‘‘)[4])#出发机场
            tmp.append(cont1[i].split(‘‘)[6])#到达机场
            tmp.append(cont1[i].split(‘‘)[20])#历时
            tmp.append(cont1[i].split(‘‘)[16])#估价
            
            self.li.append(tmp)
            i+=1

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-12-05 21:13  Search_H\
     文件       26895  2014-12-02 16:07  Search_H\MainWindow.py
     文件        8329  2014-12-01 22:51  Search_H\Player.py
     文件        9614  2014-12-01 22:52  Search_H\Player.pyc
     文件           0  2014-11-30 23:31  Search_H\__init__.py
     目录           0  2014-12-02 16:00  Search_H\build\
     目录           0  2014-12-02 16:00  Search_H\build\bdist.win32\
     目录           0  2014-12-02 16:00  Search_H\build\bdist.win32\winexe\
     目录           0  2015-01-12 21:48  Search_H\build\bdist.win32\winexe\bundle-2.7\
     目录           0  2014-12-02 16:00  Search_H\build\bdist.win32\winexe\collect-2.7\
     文件        9034  2014-12-02 16:00  Search_H\build\bdist.win32\winexe\collect-2.7\Player.pyc
     目录           0  2014-12-02 16:00  Search_H\build\bdist.win32\winexe\collect-2.7\PyQt4\
     文件         549  2014-12-02 17:11  Search_H\build\bdist.win32\winexe\collect-2.7\PyQt4\Qt.pyc
     文件         561  2014-12-02 17:11  Search_H\build\bdist.win32\winexe\collect-2.7\PyQt4\QtCore.pyc
     文件         558  2014-12-02 17:11  Search_H\build\bdist.win32\winexe\collect-2.7\PyQt4\QtGui.pyc
     文件         105  2014-12-02 16:00  Search_H\build\bdist.win32\winexe\collect-2.7\PyQt4\__init__.pyc
     文件         561  2014-12-02 17:11  Search_H\build\bdist.win32\winexe\collect-2.7\PyQt4\phonon.pyc
     文件       11100  2014-12-02 16:00  Search_H\build\bdist.win32\winexe\collect-2.7\StringIO.pyc
     文件        7920  2014-12-02 16:00  Search_H\build\bdist.win32\winexe\collect-2.7\UserDict.pyc
     文件        5442  2014-12-02 16:00  Search_H\build\bdist.win32\winexe\collect-2.7\_LWPCookieJar.pyc
     文件        4392  2014-12-02 16:00  Search_H\build\bdist.win32\winexe\collect-2.7\_MozillaCookieJar.pyc
     文件        4172  2014-12-02 16:00  Search_H\build\bdist.win32\winexe\collect-2.7\__future__.pyc
     文件       22944  2014-12-02 16:00  Search_H\build\bdist.win32\winexe\collect-2.7\_abcoll.pyc
     文件         549  2014-12-02 17:11  Search_H\build\bdist.win32\winexe\collect-2.7\_hashlib.pyc
     文件         546  2014-12-02 17:11  Search_H\build\bdist.win32\winexe\collect-2.7\_socket.pyc
     文件         537  2014-12-02 17:11  Search_H\build\bdist.win32\winexe\collect-2.7\_ssl.pyc
     文件       14495  2014-12-02 16:00  Search_H\build\bdist.win32\winexe\collect-2.7\_strptime.pyc
     文件        6424  2014-12-02 16:00  Search_H\build\bdist.win32\winexe\collect-2.7\_threading_local.pyc
     文件        8718  2014-12-02 16:00  Search_H\build\bdist.win32\winexe\collect-2.7\_weakrefset.pyc
     文件        5923  2014-12-02 16:00  Search_H\build\bdist.win32\winexe\collect-2.7\abc.pyc
     文件        2083  2014-12-02 16:00  Search_H\build\bdist.win32\winexe\collect-2.7\atexit.pyc
............此处省略346个文件信息

评论

共有 条评论

相关资源