对这个世界如果你有太多的抱怨
跌倒了就不敢继续往前走
为什么人要这么的脆弱 堕落
请你打开电视看看
多少人为生命在努力勇敢的走下去
我们是不是该知足
珍惜一切 就算没有拥有
🎵 周杰伦《稻香》
# -*- coding:utf-8 -*-
import time
from selenium import webdriver
from selenium.webdriver.edge.service import Service
option = webdriver.ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation']) # 去掉webdriver提示 + 顶层窗口
option.add_argument("--disable-blink-features=AutomationControlled") # 屏蔽webdriver特征
browser = webdriver.Chrome(options=option,executable_path="/Applications/Chromium.app/Contents/MacOS/Chromium")
with open('webdriver_check.js', 'r', encoding='utf-8') as f:
js = f.read()
browser.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": js
})
time.sleep(10000)
# -*- coding:utf-8 -*-
import time
from playwright.sync_api import sync_playwright
def main():
# 启动Playwright
with sync_playwright() as p:
# 选择浏览器引擎(chromium、firefox、webkit)
browser = p.chromium.launch(headless=False)
# 创建新的浏览器上下文
context = browser.new_context()
# 创建新的页面
page = context.new_page()
with open('webdriver_check.js', 'r', encoding='utf-8') as f:
js = f.read()
page.add_init_script(js)
# 打开网页
page.goto('https://www.baidu.com/')
# 在页面中查找并填写表单
time.sleep(500)
# 关闭浏览器
browser.close()
if __name__ == "__main__":
main()