def getCookies(qq,password,dama=False): driver=webdriver.Chrome() driver.get('http://qzone.qq.com') driver.switch_to_frame('login_frame') driver.find_element_by_id('switcher_plogin').click() driver.find_element_by_id('u').clear() driver.find_element_by_id('u').send_keys(qq) driver.find_element_by_id('p').clear() driver.find_element_by_id('p').send_keys(password) driver.find_element_by_id('login_button').click() while '验证码' in driver.page_source: try: print('需要处理验证码!') driver.save_screenshot('verification.png') if not dama: # 如果不需要打码,则跳出循环 break iframes = driver.find_elements_by_tag_name('iframe') try: driver.switch_to_frame(iframes[1]) input_verification_code = driver.find_element_by_id('cap_input') submit = driver.find_element_by_id('verify_btn') verification_code = identify() print('验证码识别结果: %s' % verification_code) input_verification_code.clear() input_verification_code.send_keys(verification_code) submit.click() except Exception: break except Exception: return '' print(driver.title) cookie = {} for elem in driver.get_cookies(): cookie[elem['name']] = elem['value'] return json.dumps(cookie) # 将字典转成字符串
def getCookie(account, password, dama=False): """ 根据QQ号和密码获取cookie """ failure = 0 while failure < 2: try: dcap = dict(DesiredCapabilities.PHANTOMJS) dcap["phantomjs.page.settings.userAgent"] = ( "Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; Nexus S Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1" ) browser = webdriver.PhantomJS(desired_capabilities=dcap) browser.get('http://qzone.qq.com/') try: access = browser.find_element_by_id('guideSkip') # 继续访问触屏版按钮 access.click() time.sleep(1) except Exception, e: pass account_input = browser.find_element_by_id('u') # 账号输入框 password_input = browser.find_element_by_id('p') # 密码输入框 go = browser.find_element_by_id('go') # 登录按钮 account_input.clear() password_input.clear() account_input.send_keys(account) password_input.send_keys(password) go.click() time.sleep(2) print "login !!!" while '验证码' in browser.page_source: try: print '需要处理验证码!' browser.save_screenshot('verification.png') if not dama: # 如果不需要打码,则跳出循环 break iframes = browser.find_elements_by_tag_name('iframe') try: browser.switch_to_frame(iframes[1]) input_verification_code = browser.find_element_by_id('cap_input') submit = browser.find_element_by_id('verify_btn') verification_code = identify() print '验证码识别结果: %s' % verification_code input_verification_code.clear() input_verification_code.send_keys(verification_code) submit.click() time.sleep(1) except Exception, e: break except Exception, e: browser.quit() return '' if browser.title == 'QQ空间': cookie = {} print "get cookie!" for elem in browser.get_cookies(): cookie[elem['name']] = elem['value'] print 'Get the cookie of QQ:%s successfully!(共%d个键值对)' % (account, len(cookie)) browser.quit() return json.dumps(cookie) # 将字典转成字符串 else: print 'Get the cookie of QQ:%s failed!' % account return ''
def getCookie(account, password, dama=False): """ 根据QQ号和密码获取cookie """ failure = 0 while failure < 2: try: dcap = dict(DesiredCapabilities.PHANTOMJS) dcap["phantomjs.page.settings.userAgent"] = ( "Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; Nexus S Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1" ) browser = webdriver.PhantomJS(desired_capabilities=dcap) browser.get('http://qzone.qq.com/') try: access = browser.find_element_by_id('guideSkip') # 继续访问触屏版按钮 access.click() time.sleep(1) except Exception, e: pass account_input = browser.find_element_by_id('u') # 账号输入框 password_input = browser.find_element_by_id('p') # 密码输入框 go = browser.find_element_by_id('go') # 登录按钮 account_input.clear() password_input.clear() account_input.send_keys(account) password_input.send_keys(password) go.click() time.sleep(2) while '验证码' in browser.page_source: try: print '需要处理验证码!' browser.save_screenshot('verification.png') if not dama: # 如果不需要打码,则跳出循环 break iframes = browser.find_elements_by_tag_name('iframe') try: browser.switch_to_frame(iframes[1]) input_verification_code = browser.find_element_by_id('cap_input') submit = browser.find_element_by_id('verify_btn') verification_code = identify() print '验证码识别结果: %s' % verification_code input_verification_code.clear() input_verification_code.send_keys(verification_code) submit.click() time.sleep(1) except Exception, e: break except Exception, e: browser.quit() return '' if browser.title == 'QQ空间': cookie = {} for elem in browser.get_cookies(): cookie[elem['name']] = elem['value'] print 'Get the cookie of QQ:%s successfully!(共%d个键值对)' % (account, len(cookie)) browser.quit() return json.dumps(cookie) # 将字典转成字符串 else: print 'Get the cookie of QQ:%s failed!' % account return ''
driver2.get("http://mousehuntgame.com") username = driver2.find_element_by_name("accountName") username.send_keys("curtisxuan") password = driver2.find_element_by_name("password") password.send_keys("uzumakinaruto") loginButton = driver2.find_element_by_name("doLogin") loginButton.click() image = driver2.find_element_by_id("puzzleImage") driver2.save_screenshot("bb.png") x = int(image.location["x"]) y = int(image.location["y"]) im = Image.open("bb.png") im.crop((x - 5, y, 150 + x, y + 50)).save("bc.png") code_txt = "" if count < 2: code_txt = identify() count = count + 1 code = driver2.find_element_by_id("puzzle_answer") code.send_keys(code_txt) submit = driver2.find_element_by_id("puzzle_submit") submit.click() time.sleep(3) driver2.quit() driver.get("http://mousehuntgame.com") if not "Click here to claim" in driver.find_element_by_id( "hornMessage").text: count = 0 time.sleep(5) """find lucky tower""" # img = driver.find_element_by_class_name("riftBristleWoodsHUD-chamberTitle") # x = int(img.location["x"])
def getCookie(account, password, dama=True): """ 根据QQ号和密码获取cookie """ failure = 0 while failure < 2: try: # options = webdriver.ChromeOptions() # # 设置无图模式 # prefs = { # 'profile.default_content_setting_values': { # 'images': 2 # } # } # options.add_argument('--headless') # 浏览器隐藏 # options.add_argument('disable-infobars') # 去除显示受控制 # options.add_argument('--disable-gpu') # options.add_experimental_option('prefs', prefs) # 设置无图模式 # # browser = webdriver.Chrome(chrome_options=options, # executable_path='/Users/ozintel/Downloads/Tsl_python_progect/znfw_project/znfw_crawer/simulation_browser_crawer/chromedriver') dcap = dict(DesiredCapabilities.PHANTOMJS) dcap["phantomjs.page.settings.userAgent"] = ( "Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; Nexus S Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1" ) browser = webdriver.PhantomJS( desired_capabilities=dcap, executable_path= '/Users/ozintel/Downloads/Tsl_python_progect/znfw_project/znfw_crawer/simulation_browser_crawer/phantomjs-2.1.1-macosx/bin/phantomjs' ) browser.get('http://qzone.qq.com/') try: access = browser.find_element_by_id('guideSkip') # 继续访问触屏版按钮 access.click() time.sleep(3) except Exception as e: pass account_input = browser.find_element_by_id('u') # 账号输入框 password_input = browser.find_element_by_id('p') # 密码输入框 go = browser.find_element_by_id('go') # 登录按钮 account_input.clear() password_input.clear() account_input.send_keys(account) password_input.send_keys(password) go.click() time.sleep(3) while '验证码' in browser.page_source: try: print('需要处理验证码!') browser.save_screenshot('verification.png') if not dama: # 如果不需要打码,则跳出循环 break iframes = browser.find_elements_by_tag_name('iframe') try: browser.switch_to.frame(iframes[1]) input_verification_code = browser.find_element_by_id( 'cap_input') submit = browser.find_element_by_id('verify_btn') verification_code = identify() print('验证码识别结果: %s' % verification_code) input_verification_code.clear() input_verification_code.send_keys(verification_code) submit.click() time.sleep(3) except Exception as e: break except Exception as e: browser.quit() return '' if browser.title == 'QQ空间': cookie = {} for elem in browser.get_cookies(): cookie[elem['name']] = elem['value'] print('Get the cookie of QQ:%s successfully!(共%d个键值对)' % (account, len(cookie))) browser.quit() return json.dumps(cookie) # 将字典转成字符串 else: print('Get the cookie of QQ:%s failed!' % account) return '' except Exception as e: failure = failure + 1 if 'browser' in dir(): browser.quit() except KeyboardInterrupt as e: raise e return ''
def crawl(_): filename = '%s.png' % str(uuid1()) try: session = requests.Session() session.headers = { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'Host': 'm.xuekubao.com', 'Upgrade-Insecure-Requests': '1', 'User-Agent': 'Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; Nexus S Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1', } session.get('http://m.xuekubao.com/shiti/710240.shtml') session.headers = { 'Accept': 'image/webp,image/apng,image/*,*/*;q=0.8', 'Host': 'm.xuekubao.com', 'Referer': 'http://m.xuekubao.com/shiti/710240.shtml', 'User-Agent': 'Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; Nexus S Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1' } r = session.get( 'http://m.xuekubao.com/index.php?m=Show&a=verify&tid=710240', timeout=10) if r.status_code != 200: print 'status_code: %s' % r.status_code time.sleep(2) return with open(filename, 'wb') as f: f.write(r.content) code = identify(filename, codetype=1004) if len(code) != 4: raise Exception('identify failed.') data2 = {'code': code, 'tid': '710240'} session.headers = { 'Accept': 'application/json, text/javascript, */*; q=0.01', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'Host': 'm.xuekubao.com', 'Origin': 'http://m.xuekubao.com', 'Referer': 'http://m.xuekubao.com/shiti/710240.shtml', 'User-Agent': 'Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; Nexus S Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1', 'X-Requested-With': 'XMLHttpRequest' } r2 = session.post('http://m.xuekubao.com/index.php?m=Show&a=imgcheck', data=data2, timeout=10) if '{"error":1}' not in r2.content: shutil.move( filename, './captchas/%s---%s.png' % (filename.split('.')[0], code)) print '%s: successful: %s --> %s' % (datetime.datetime.now(), filename, code) else: print 'failed: %s' % filename except Exception, e: print e