from selenium import webdriver
import time
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
def getWeb(url):
'''配置web浏览器'''
options = webdriver.ChromeOptions()
mobile_emulation = {"deviceName": "Galaxy S5"}
capabilities = DesiredCapabilities.CHROME
capabilities['loggingPrefs'] = {'browser': 'ALL'}
options.add_experimental_option("mobileEmulation", mobile_emulation)
options.add_experimental_option('excludeSwitches', ['enable-automation'])
options.add_argument(
'user-agent=mozilla/5.0 (iphone; cpu iphone os 5_1_1 like mac os x) applewebkit/534.46 (khtml, like gecko) mobile/9b206 micromessenger/5.0')
prefs = {'permissions.default.stylesheet': 2}
options.add_experimental_option("prefs", prefs)
options.headless = True
web = webdriver.Chrome(options=options)
url = "https://work.zcst.edu.cn/default/work/jlzh/jkxxtb/jkxxcj.jsp"
web.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": """
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
"""
})
web.set_page_load_timeout(30)
web.set_script_timeout(30)
web.get(url)
return web
|