def round_trip(DepartCity, ReturnCity, departDate, returnDate, debug=0): #global se start_time = datetime.now() url = 'http://flights.ctrip.com/international/round-%s-%s-%s-%s?%s&%s&y_s' % ( DepartCity, ReturnCity, code(DepartCity), code(ReturnCity), departDate, returnDate) #print(url) ctrip_access = False while ctrip_access == False: se = Session(Ghost(), wait_timeout=30, wait_callback=None, display=True, viewport_size=(800, 680), download_images=False) se.delete_cookies() proxy = choice(proxypool) se.set_proxy(proxy[0], proxy[1], int(proxy[2])) try: se.open(url, user_agent=choice(ua_list)) #print('已打开 %s' % url) except: se.exit() del se proxypool.remove(proxy) print("blacklist %s" % proxy[1]) continue ctrip_access = se.exists('li:nth-child(5) > span') if ctrip_access == False: se.exit() del se proxypool.remove(proxy) print("blacklist %s" % proxy[1]) se.click('#sortControls > ul > li:nth-child(5) > span') if se.exists('i.icon-reverse') == True: se.click('#sortControls > ul > li:nth-child(5) > span') se.wait_while_selector('#FI_progBar', timeout=20) #print('Loading finished!') se.sleep(0.2) html = se.content soup = BeautifulSoup(html, "html.parser") source = soup.select('#flightList > div') if debug == 1: return source lowest = source[0].select('span.price2')[0].text end_time = datetime.now() timedelsta = (end_time - start_time).seconds print('%s-%s往返 %s去 %s回 最低价%s 搜索耗时%s秒' % (DepartCity, ReturnCity, departDate, returnDate, lowest, timedelsta)) se.exit() del se price = lowest[1:] insert_price(DepartCity, ReturnCity, departDate, returnDate, price)
item_url = 'http://www.supremenewyork.com/shop/accessories/oi6nqp83m/hsyw4g52m' checkout_url = 'https://www.supremenewyork.com/checkout' ############################## ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36' header = {'User-Agent': ua} gh = Ghost() se = Session(gh, user_agent=ua, wait_timeout=20, wait_callback=None, display=True, viewport_size=(1080, 1680), download_images=True) ############################## se.open(item_url) se.evaluate("""document.querySelector('input[name="commit"]').click();""") se.sleep(0.5) se.open(checkout_url) ISOFORMAT = '%Y%m%d' today = datetime.today() filename = today.strftime(ISOFORMAT) f = open('supreme' + '/' + filename + '.html', 'w') f.write(se.content) f.close() import code code.interact(banner="", local=locals())