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

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

資源簡介

這個版本是最優化版本,可以不斷的輸入想要爬取的時間,地點,不斷的爬取,使用了GUI,使得可以根據自己選擇某一天來查詢機票價格,或者未來90天的價格,可以根據自己輸入的始發地,目的地,日期,然后自動爬取該天全部機票的票價,航班,發機時間,還有可以自動保存到excel里面,同時是用來學習爬取網絡一個好的例子,最主要的是能自動保存到excel里面,文件名字都是根據自己來輸入,很智能化,python爬蟲最終版本我相信不會讓大家失望,真的真的很互動也很智能,如果好用,麻煩給個好評,至于最后爬取內容是在文檔那個文件夾里面

資源截圖

代碼片段和文件信息

#!/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
import?win32com.client?as?win32
import?win32gui
import?requests
from?tkinter?import?*
import?sys
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?=?[]
go_On?=?True
def?oneDay_ticket():
try:
global?soup
adrress_start?=?input(‘Please?input?a?StartAdrress:‘)
adrres_end?=?input(‘Please?input?a?EndAdrress:‘)
GoDate?=?input(‘Please?input?a?Date:‘)
name?=?input(‘Please?input?filename:‘)
dest_filename?=?‘%s.xlsx‘%?name
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
sh.Cells(14).Value?=?‘價格(元)‘
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=‘D:/Python/Python_work/phantomjs-2.1.1-windows/bin/phantomjs‘)
driver.get(url)
time.sleep(3)
sourcePage?=?driver.page_source
soup?=?BeautifulSoup(sourcePage?“lxml“)
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?+?22).Value?=?start_t
sh.Cells(num?+?23).Value?=?end_t
sh.Cells(num?+?24).Value?=?a_price
num?+=1
sh.Cells.Replace(“¥“““)
sh.Cells.Columns.AutoFit
sh.SaveAs(dest_filename)
finally:
wb.Close(False)
xl.Application.Quit()
#

評論

共有 條評論