文章转载于:selenium也能过某数、5s盾…
直接安装:
pip install undetected_chromedriver
运行代码:
import undetected_chromedriver as uc
import timedriver = uc.Chrome(executable_path=r'C:\Users\chromedriver.exe',version_main=111)
driver.get('网址')
time.sleep(20)
print(driver.page_source)
print(driver.get_cookie())
神奇的地方就在源码里面:
另外一个神奇的库:
pip install selenium-wire
from seleniumwire.undetected_chromedriver.v2 import Chrome, ChromeOptions
import time,gzipif __name__ == '__main__':options = {}chrome_options = ChromeOptions()chrome_options.add_argument("--disable-gpu")chrome_options.add_argument("--incognito")chrome_options.add_argument("--disable-dev-shm-usage")chrome_options.add_argument("--headless")# chrome_options.add_argument(f"--proxy-server=http://192.168.100.24:60021")chrome_options.add_argument("--disable-popup-blocking")chrome_options.add_argument("--profile-directory=Default")chrome_options.add_argument("--ignore-certificate-errors")chrome_options.add_argument("--disable-plugins-discovery")chrome_options.add_argument('--no-first-run')chrome_options.add_argument('--no-service-autorun')chrome_options.add_argument('--no-default-browser-check')chrome_options.add_argument('--password-store=basic')chrome_options.add_argument('--no-sandbox')browser = Chrome(seleniumwire_options=options, options=chrome_options,executable_path=r'C:\Users\chromedriver.exe',version_main=111)browser.get('网址')time.sleep(35)print(browser.page_source)for request in browser.requests:if request.response:print(request.path)if 'getZxajslData' in request.path:# if 'shipments' in request.path:# print(request.response.body)#获取内容为乱码可尝试用以下方法解码print(gzip.decompress(request.response.body).decode("utf-8"))
这个库的优点就是能获取打开这个页面后,发出请求返回的结果,灰常好用
奇怪的是这个库明明也使用了undetected_chromedriver
,但是访问相同的网站却需要验证。