MCPcopy Index your code
hub / github.com/lining0806/PythonSpiderNotes / one_driver_ticket

Function one_driver_ticket

QunarSpider/QunarSpider.py:20–67  ·  view source on GitHub ↗
(driver, from_city, to_city)

Source from the content-addressed store, hash-verified

18
19
20def one_driver_ticket(driver, from_city, to_city):
21 # time = datetime.datetime.now()
22 date = datetime.date.today()
23 tomorrow = date+datetime.timedelta(days=1)
24 # date格式转为string格式
25 tomorrow_string = tomorrow.strftime('%Y-%m-%d')
26
27 driver.find_element_by_name('fromCity').clear()
28 driver.find_element_by_name('fromCity').send_keys(from_city)
29 driver.find_element_by_name('toCity').clear()
30 driver.find_element_by_name('toCity').send_keys(to_city)
31 driver.find_element_by_name('fromDate').clear()
32 driver.find_element_by_name('fromDate').send_keys(tomorrow_string)
33 driver.find_element_by_xpath('//button[@type="submit"]').click()
34 time.sleep(5) # 控制间隔时间,等待浏览器反映
35
36 flag = True
37 page_num = 0
38 while flag:
39 # 保存页面
40 # print driver.page_source
41 source_code = driver.find_element_by_xpath("//*").get_attribute("outerHTML")
42 print type(source_code)
43 dstdir = u'./ticket/'
44 if not exists(dstdir):
45 makedirs(dstdir)
46 f = codecs.open(dstdir+from_city+u','+to_city+unicode(tomorrow_string)+u','+unicode(str(page_num+1))+u'.html', 'w+', 'utf8')
47 f.write(source_code)
48 f.close()
49
50 next_page = None
51 try:
52 next_page = driver.find_element_by_id('nextXI3')
53 except Exception as e:
54 print e
55 pass
56 print "page: %d" % (page_num+1)
57 if next_page:
58 try:
59 next_page.click()
60 time.sleep(2) # 控制间隔时间,等待浏览器反映
61 page_num += 1
62 except Exception as e:
63 print 'next_page could not be clicked'
64 print e
65 flag = False
66 else:
67 flag = False
68
69def get_proxy_list(file_path):
70 proxy_list = []

Callers 2

ticket_worker_proxyFunction · 0.85
ticket_worker_no_proxyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected