某些原因需要自动截图。。
参考文档:
操作cookie:https://blog.csdn.net/ytraister/article/details/106033630
参数: https://blog.csdn.net/weixin_43968923/article/details/87899762
https://blog.csdn.net/m0_50944918/article/details/113185800
鼠标点击: http://www.360doc.com/content/22/1112/08/65839882_1055570473.shtml
模拟手机:https://blog.csdn.net/xiao_yi_xiao/article/details/122220828
安装环境: https://blog.csdn.net/zxp3817100/article/details/125089490
Linux系统需要安装中文字体支持
获取cookie可以先不使用–headless
1 2 3 time.sleep(200 ) print (json.dumps(driver.get_cookies())) driver.close()
转换cookie时如果里面有中文不要转义ascii
1 json.dumps(login_ret, ensure_ascii=False )
最终代码:
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 import jsonimport urllib.parseimport requestsfrom selenium import webdriverfrom selenium.webdriver.chrome.options import Optionsfrom selenium.webdriver.chrome.service import Servicefrom selenium.webdriver.common.by import Byfrom selenium.webdriver.common.action_chains import ActionChainsimport timeif __name__ == '__main__' : options = Options() options.add_argument('--no-sandbox' ) options.add_argument('--headless' ) options.add_argument('--disable-gpu' ) options.add_argument('--hide-scrollbars' ) options.add_argument('lang=zh_CN.UTF-8' ) prefs = {"credentials_enable_service" : False , "profile.password_manager_enabled" : False } options.add_experimental_option("prefs" , prefs) options.add_experimental_option('excludeSwitches' , ['enable-automation' ]) options.add_argument( 'user-agent=Mozilla/5.0 (Linux; U; Android 11; zh-CN; GM1910 Build/RKQ1.201022.002) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/69.0.3497.100 UWS/3.22.1.233 Mobile Safari/537.36 AliApp(DingTalk/6.5.45) com.alibaba.android.rimet/26284409 Channel/263200 language/zh-CN abi/64 UT4Aplus/0.2.25 colorScheme/light' ) driver = webdriver.Chrome(service=Service('D:\ChromeData\chromedriver.exe' ), options=options) driver.set_window_size(width=412 , height=915 ) driver.get('http://xxxxxx' ) driver.delete_all_cookies() driver.add_cookie( {"domain" : "xxx" , "httpOnly" : False , "name" : "auth_user" , "path" : "/" , "secure" : False , "value" : encode_login_ret}) driver.add_cookie({"domain" : "xxx" , "httpOnly" : True , "name" : "JSESSIONID" , "path" : "/xxxx" , "secure" : False , "value" : '你的cookie' }) driver.get('http://xxxx' ) time.sleep(2 ) time.sleep(3 ) driver.get_screenshot_as_file('./tmp.png' ) driver.close()