Add cookie python-webdriver, the added image verification code to solve the problem

Encounter problems: Before you can use the script has suddenly run nowhere, a closer look at the original research and development added a new picture verification code ......

To solve the problem: grab a cookie and manually inserted to solve the problem. Of course, if your cookie is valid or too short, with the session closed on failure, this approach is not appropriate.

Code First Edition:

def Login(driver):
cookies = { 'name': 'wx_sid', 'value': '43064da8ec6a117d16c34b59bdf6116abys4s99***'}
    driver.add_cookie(cookies)
  driver.get("http://admin.***.com/index/login")
    driver.quit () 
IF __name__ __ == '__ main__':
Driver = webdriver.Chrome (executable_path = "d: \\ chromedriver")
the Login (Driver)

found no access to the specified address after launching the browser is executed, the online information The reason is not found where the plug when stuffed cookie. The solution is to join domain or about the first visit to stuffed link address.

Code Second Edition:
the Login DEF (Driver): 

driver.get ( "HTTP: //admin.***.com/index/login")
Cookies = { 'name': 'wx_sid', 'value': '43064da8ec6a117d16c34b59bdf6116abys4s99 ***', 'path': '/', 'Domain': '.. COM .Admin ***'}
driver.add_cookie (Cookies)
driver.get ( "HTTP: //admin.***.com/index")

IF __ == __name__ '__ main__':
Driver = webdriver.Chrome (executable_path = "d: \\ chromedriver")
the Login (Driver)
after the first visit or found not fit into, and then check the information, the solution is the need to refresh the page.

Code Third Edition:
the Login DEF (Driver): 

driver.get ( "HTTP: //admin.***.com/index/login")
Cookies = { 'name': 'wx_sid', 'value': '43064da8ec6a117d16c34b59bdf6116abys4s99 ***', 'path': '/', 'Domain': '.Admin *** COM..'}
driver.add_cookie (Cookies)
driver.refresh () # refresh the page
driver.get ( "http: //admin.** .com * / index ")

IF __name__ __ == '__ main__':
Driver = webdriver.Chrome (executable_path =" D: \\ chromedriver ")
the Login (Driver)

refresh finally succeeded, switching environment, the line to cut from the test environment on the environment, performed again and failed repeatedly to find a cause, and finally .... online environment with the cookie name is wx this, the test environment due to the conflict with other developing its own into a wx_sid ... so to remind junior partner, the cookie in the end should correspond best to confirm with good R & D use which.
The final version of the online environment Code:
def Login(driver):

driver.get("http://admin.***.com/index/login")
# 线上环境
cookies = { 'name': 'wx', 'value': '43064da8ec6a117d16c34b59bdf6116abys4s99***','path': '/','domain': '.admin.***.com'}
driver.add_cookie(cookies)
driver.refresh()
driver.get("http://admin.***.com/index")

if __name__=='__main__':
driver = webdriver.Chrome(executable_path="d:\\chromedriver")
Login(driver)


Guess you like

Origin www.cnblogs.com/qingqing-919/p/11230200.html