Python selenium模拟搜索无法获得结果

由于课程需求,想要用selenium爬取维普中文期刊(http://qikan.cqvip.com/Qikan/...)以“植物修复 镉”为关键词搜索到的所有论文基本信息,由于维普搜索时网址不变,所以打算进行模拟搜索,但是vscode执行后代码后页面变空白,程序本身没有报错,更换网络后也没有解决,请问是怎么回事?我该如何解决?

搜索页面截图:
image.png

模拟搜索后截图:

真实浏览器搜索结果(理想结果)截图:
image.png

以下是代码:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By
import pandas as pd
import os

os.chdir(os.path.dirname(__file__))
data = pd.DataFrame(columns=['title', 'authors', 'journal', 'date'])

# 实体化模拟浏览器
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-automation', 'enable-logging'])  # 消去报错
options.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2})  # 不加载图片
browser = webdriver.Chrome(options=options)

# 反selenium检测
browser.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
  "source": """
    Object.defineProperty(navigator, 'webdriver', {
      get: () => undefined
    })
  """
})

# 模拟搜索
browser.get('http://qikan.cqvip.com/Qikan/Search/Index?from=index')
WebDriverWait(browser, 30, poll_frequency=0.1).until(expected_conditions.presence_of_element_located((By.XPATH, '//*[@id="searchKeywords"]')))  # 等待搜索框加载
browser.find_element(By.XPATH, '//*[@id="searchKeywords"]').clear()  # 清楚搜索框原有内容
browser.find_element(By.XPATH, '//*[@id="searchKeywords"]').send_keys('植物修复 镉')  # 输入关键词
browser.find_element(By.XPATH, '//*[@id="btnSearch"]').click()  # 点击搜索
阅读 974
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进