Exemplo n.º 1
0
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)
Exemplo n.º 2
0
def login_qq():
    global se
    ua_m = 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_1_1 like Mac OS X) AppleWebKit/604.3.5 (KHTML, like Gecko) Version/11.0 Mobile/15B150 Safari/604.1'
    se = Session(Ghost(),
                 user_agent=ua_m,
                 wait_timeout=30,
                 wait_callback=None,
                 display=True,
                 viewport_size=(375, 553),
                 download_images=True)
    url = 'https://ui.ptlogin2.qq.com/cgi-bin/login?style=38&appid=728041403&s_url=https%3A%2F%2Finfoapp.3g.qq.com%2Fg%2Flogin%2Fproxy.jsp%3FsourceUrl%3Dhttps%25253A%25252F%25252Fportal.3g.qq.com%25252F%25253F_r%25253D0.2646472700205946%252526aid%25253Dindex%252526g_f%25253D1283&target=self&low_login=1&low_login_hour=4321&daid=261&islogin=false&uid=-8794356048489038000'
    se.open(url)
    se.set_field_value('#u', '2873723285')
    se.set_field_value('#p', 'tz1006')
    se.click('#go', expect_loading=True)
Exemplo n.º 3
0
    
url = 'https://trade.cgws.com/cgi-bin/user/Login'
se.open(url)
# username
se.set_field_value('#fundAccount', username)
# password
se.fire('#normalpassword', 'focus')
se.show()
html = se.content
soup =  BeautifulSoup(html, "html.parser")
keys = soup.select('tbody > tr > td')
key_list = []
for key in keys:
    key_list.append(key.text)

for i in password:
    m = (key_list.index(i) // 4) + 1
    n = (key_list.index(i) % 4) + 1
    se.click('tbody > tr:nth-child(%s) > td:nth-child(%s)' % (m, n))

#se.click('tbody > tr:nth-child(2) > td:nth-child(2)')
se.capture_to('s/vcode.png', selector='#ticketImg')
image = Image.open('s/vcode.png')
vcode = pytesseract.image_to_string(image)
se.set_field_value('#ticket', vcode)
#se.click('#submit')
    
    


Exemplo n.º 4
0
#!/usr/bin/env python
#coding:utf-8

from ghost import Ghost, Session
import time
if __name__ == '__main__':
    gh = Ghost()
    se = Session(gh, display=True)
    se.open("https://www.baidu.com/")
    se.show()  #完成输入后要刷新
    se.fill("#kw", "hello world")
    se.click("#su", btn=0)
    se.show()  #完成输入后要刷新
    time.sleep(10)
#!/usr/bin/env python
#coding:utf-8

from ghost import Ghost, Session
import time
if __name__ == '__main__':
    gh = Ghost()
    se = Session(gh, display = True)
    se.open("https://www.baidu.com/")
    se.show()#完成输入后要刷新
    se.fill("#kw","hello world")
    se.click("#su",btn=0) 
    se.show()#完成输入后要刷新
    time.sleep(10)