91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 5KB
    文件類型: .py
    金幣: 2
    下載: 1 次
    發布日期: 2021-06-05
  • 語言: Python
  • 標簽: python??seleni??

資源簡介

爬取某一天攜程機票,可以根據自己輸入的始發地,目的地,日期,然后自動爬取該天全部機票的票價,航班,發機時間,還有可以自動保存到excel里面,同時是用來學習爬取網絡一個好的例子,最主要的是能自動保存到excel里面

資源截圖

代碼片段和文件信息

#!/usr/bin/env?python
from?selenium.webdriver.common.by?import?By
from?selenium.webdriver.support.ui?import?WebDriverWait
from?selenium.webdriver.support?import?expected_conditions?as?EC
from?selenium?import?webdriver
import?time
from?datetime?import?datetime
from?dateutil.parser?import?parse
from?bs4?import?BeautifulSoup
import?re
from?lxml?import?etree
import?win32com.client?as?win32

headers?=?{
‘User-Agent‘:‘Mozilla/5.0?(Windows?NT?10.0;?WOW64)?AppleWebKit/537.36?(KHTML?like?Gecko)?Chrome/63.0.3239.132?Safari/537.36?QIHU?360SE‘
‘Accept‘:‘text/htmlapplication/xhtml+xmlapplication/xml;q=0.9image/webpimage/apng*/*;q=0.8‘
‘Connection‘:‘keep-alive‘
‘Accept-Encoding‘:‘gzip?deflate?br‘
}

city?=?{
‘上海‘:‘sha‘‘北京‘:‘bjs‘‘廣州‘:‘can‘‘深圳‘:‘szx‘
‘??凇?‘hak‘‘三亞‘:‘syx‘‘杭州‘:‘hgh‘‘武漢‘:‘wuh‘
‘成都‘:‘ctu‘‘西安‘:‘sia‘‘重慶‘:‘ckg‘‘青島‘:‘tao‘
‘長沙‘:‘csx‘‘南京‘:‘nkg‘‘廈門‘:‘xmn‘‘昆明‘:‘kmg‘
‘大連‘:‘dlc‘‘天津‘:‘tsn‘‘鄭州‘:‘cgo‘‘濟南‘:‘tna‘
‘福州‘:‘foc‘
}

all_price?=?[]
result?=?[]
adrress_start?=?input(‘Please?input?a?StartAdrress:‘)
adrres_end?=?input(‘Please?input?a?EndAdrress:‘)
GoDate?=?input(‘Please?input?a?Date:‘)

dest_filename?=?‘機票2.xlsx‘
app?=?‘Excel‘
xl?=?win32.gencache.EnsureDispatch(‘%s.Application‘?%?app)
wb?=?xl.Workbooks.Add()
sh?=?wb.ActiveSheet
sh.Cells.NumberFormatLocal?=?“@“
xl.Visible?=?True
sh.Cells(11).Value?=?adrress_start
sh.Cells(12).Value?=?adrres_end

GoDate?=?str(GoDate)
if?GoDate!=‘‘:

GoDate?=?parse(GoDate)
GoDate?=?GoDate.strftime(‘%Y-%m-%d‘)
sh.Cells(13).Value?=?GoDate
else:
GoDate?=?datetime.today()
GoDate?=?GoDate.strftime(‘%Y-%m-%d‘)
sh.Cells(13).Value?=?GoDate
#?~?GoDate.asctime()

id_list?=?re.compile(r‘[a-zA-Z0-9\._+-]*‘)
adrress_start?=?city.get(adrress_start)
adrres_end?=?city.get(adrres_end)
link?=?‘{}-{}?date={}‘
links?=?link.format(adrress_startadrres_endGoDate)

url?=?‘https://flights.ctrip.com/itinerary/oneway/‘+links
expression?=?re.compile(r‘^\/itinerary\/oneway\/[a-z]+[\-]+[a-z]+\?date\=[0-9]+[-]+[0-9]+[-]+[0-9]+‘)
driver?=?webdriver.PhantomJS(executable_path=‘F:/書籍/Python/Python_work/phantomjs-2.1.1-windows/bin/phantomjs‘)
driver.get(url)

def?main():

num?=?0
inb_find()
price()
result_ls()
for?(namestart_tend_ta_price)?in?zip(airport_namestart_timeend_timeall_price):
sh.Cells(num?+?21).Value?=?name?
sh.Cells(num?+?

評論

共有 條評論