无头浏览器
from selenium import webdriver
from time import sleep
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
bro = webdriver.Chrome(executable_path='./chromedriver.exe',chrome_options=chrome_options)
bro.get('https://www.baidu.com')
sleep(2)
print(bro.page_source)
bro.save_screenshot('1.png') #截图,后缀必须是png
sleep(2)
bro.quit()
规避请求
from selenium import webdriver
from selenium.webdriver import ChromeOptions
option = ChromeOptions()
option.add_experimental_option('excludeSwitches',['enable-automation'])
bro = webdriver.Chrome(executable_path='./chromedriver.exe',options=option)
bro.get('https://www.taobao.com')
fram导致获取节点失败
采用逐级节点切换进入到目标element存在的fram
bro.swich_fram.fram("fram平行节点ID或name")
bro.swich_fram.fram("fram子节点ID或name")
bro.swich_fram.parent_fram("fram父节点ID或name")
网友评论