简介说明 安装部署 常用下网站
问题 selenium.common.exceptions.WebDriverException: Message: newSession 参考链接:https://blog.csdn.net/qq_29012939/article/details/86591383
解决方法:
1 2 3 4 5 1、我用的浏览器是火狐浏览器,主要原因是geckodriver的版本太低,而浏览器的版本是64.0。 更新为v0.23.0:https://github.com/mozilla/geckodriver/releases 将下载下来的geckodriver.exe放入python安装路径下的Scripts文件夹内
selenium.common.exceptions.InvalidSessionIdException: Message: Tried to run command without establishing a connection 解决方法
案例-模拟淘宝登录 [Python 模拟登录]https://blog.csdn.net/u014044812/article/details/99584382
参考链接:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 from selenium import webdriverfrom time import sleepfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilitiesfrom selenium.webdriver.common.action_chains import ActionChainsfrom selenium.webdriver.common.keys import Keysimport urllib2import jsonimport tracebackimport sysdriver = webdriver.Firefox() driver.get("https://login.taobao.com/member/login.jhtml?from=taobaoindex&f=top&style=&sub=true&redirect_url=https%3A%2F%2Fmyseller.taobao.com%2Fseller_admin.htm" ) element=WebDriverWait(driver,60 ).until(lambda driver : driver.find_element_by_xpath("//*[@id='J_Quick2Static']" )) element.click() driver.implicitly_wait(20 ) sleep(1 ) username=driver.find_element_by_name("TPL_username" ) if not username.is_displayed: driver.implicitly_wait(20 ) driver.find_element_by_xpath("//*[@id='J_Quick2Static']" ).click() driver.implicitly_wait(20 ) sleep(2 ) name = "12312312@qq.com" passwd = "123123" username.send_keys(name) username.send_keys(Keys.TAB) driver.implicitly_wait(20 ) sleep(2 ) pwc=driver.find_element_by_name("TPL_password" ) pwc.send_keys(passwd) sleep(1 ) driver.save_screenshot('login-screeshot-1.png' ) sleep(2 ) while True : try : show=driver.find_element_by_xpath("//*[@id='nocaptcha']" ) showval=show.value_of_css_property("display" ) if not show.is_displayed(): break source=driver.find_element_by_xpath("//*[@id='nc_1_n1z']" ) sleep(3 ) action = ActionChains(driver) sleep(1 ) action.click_and_hold(source).perform() for index in range (20 ): try : action.move_by_offset(2 , 0 ).perform() driver.save_screenshot('login-screeshot-i-' +str (index)+'.png' ) except Exception as e: print (e) break if (index==19 ): action.release() sleep(1 ) driver.save_screenshot('login-screeshot-i-' +str (index)+'.png' ) else : sleep(0.01 ) sleep(0.1 ) sleep(2 ) driver.save_screenshot('login-screeshot-0.png' ) text=driver.find_element_by_xpath("//*[@id='nc_1__scale_text']/span" ) if text.text.startswith(u'验证通过' ): print ('成功滑动' ) break if text.text.startswith(u'请点击' ): print ('成功滑动' ) break if text.text.startswith(u'请按住' ): continue except Exception as e: print (traceback.format_exc()) print (e) print "111111111111111111111" import time time.sleep(10 ) driver.find_element_by_xpath("//*[@id='J_SubmitStatic']" ).click() sleep(2 ) driver.save_screenshot('login-screeshot-2.png' ) cookie = [item["name" ] + "=" + item["value" ] for item in driver.get_cookies()] cookiestr = ';' .join(item for item in cookie) data={ 'cookie' :cookiestr} print (data)try : headers = {'Content-Type' : 'application/json' } request = urllib2.Request(url='http://127.0.0.1:8080/update/taobao/cookie' , headers=headers, data=json.dumps(data)) response = urllib2.urlopen(request) print (response.read()) except Exception as e: print (e) driver.quit() sys.exit(0 )
案例-模拟 B 站登录 https://blog.csdn.net/qq_36853469/article/details/100579355
附件 参考链接 selenium 变速移动验证码滑块