selenium, pyppeteer 如何避免被服务器检测

1.selenium 处理方法

from selenium import webdriver
from selenium.webdriver import ChromeOptions


def get_cookie():
    option = ChromeOptions()
    option.add_experimental_option('excludeSwitches', ['enable-automation'])  # 以键值对的形式加入参数
    driver = webdriver.Chrome(executable_path="./chromedriver", options=option)
    driver.get('http://wenshu.court.gov.cn')
    cookie = driver.get_cookies()
    print(cookie)


get_cookie()

2. pyppeteer 处理方法

import asyncio
from pyppeteer import launch
from pyppeteer import launcher
from pyquery import PyQuery as pq
launcher.AUTOMATION_ARGS.remove("--enable-automation")

async def main():
    browser = await launch(headless=False)
    page = await browser.newPage()
    await page.goto('http://wenshu.court.gov.cn/')
    doc = pq(await page.content())
    print('Quotes:', doc('.quote').length)
    # await browser.close()

asyncio.get_event_loop().run_until_complete(main())

你可能感兴趣的:(python)