baidu-reporter/tests/test_dp.py

45 lines
1.3 KiB
Python
Raw Normal View History

2025-03-28 18:23:30 +08:00
from DrissionPage import Chromium, ChromiumOptions
def md5_hash(text: str):
"""计算文本的 MD5 哈希值"""
import hashlib
return hashlib.md5(text.encode()).hexdigest()
chrome_opts = ChromiumOptions()
chrome_opts.mute(True) # 静音
chrome_opts.no_imgs(False)
chrome_opts.set_argument("--disable-gpu")
chrome_opts.set_argument('--ignore-certificate-errors')
chrome_opts.set_argument("--proxy-server=http://127.0.0.1:7890")
chrome_opts.incognito(True)
chrome_opts.set_browser_path(r"C:\Program Files\Google\Chrome\Application\chrome.exe")
browser = Chromium(addr_or_opts=chrome_opts)
domain = "www.yunzhiju.net"
keyword = "www.yunzhiju.net/zxysx/9850.html"
# tab = browser.new_tab(f"https://www.baidu.com/s?wd={keyword}")
# tab = browser.new_tab(f"https://ip.im")
tab = browser.new_tab(f"https://www.baidu.com/s?wd={keyword}")
# tab.wait.eles_loaded('#timeRlt')
# time_rtl_el = tab.ele('#timeRlt')
# print(time_rtl_el.text)
# time_rtl_el.click(by_js=True)
# tab.wait.eles_loaded("@class:time_pop_")
# week_btn_el = tab.ele('t:li@@text()= 一月内 ')
# week_btn_el.click(by_js=True)
# tab.wait(2)
if "未找到相关结果" in tab.html:
print("未找到相关结果")
else:
print("找到相关结果")
img_path = f"./imgs/{domain}/{md5_hash(keyword)}.png"
print(img_path)
tab.get_screenshot(img_path)