You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Selenium从Interpol红色通缉令页面获取人员姓名

获取Interpol红色通缉令详情页的人员姓名

实现步骤:

  • 替换固定等待时间为显式等待,避免因页面加载速度差异导致的元素定位失败
  • 定位详情页中的人员姓名元素,提取其文本内容

完整代码示例:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

chromedriver_path = r"./driver/chromedriver"
browser = webdriver.Chrome(executable_path=chromedriver_path)
url = "https://www.interpol.int/en/How-we-work/Notices/View-Red-Notices"

try:
    browser.get(url)
    # 等待第一个通缉令条目加载完成并点击
    first_notice = WebDriverWait(browser, 20).until(
        EC.element_to_be_clickable((By.XPATH, '//*[@id="noticesResultsItemList"]/div[1]/div/div/div[2]/div[1]/a'))
    )
    first_notice.click()
    
    # 等待详情页姓名元素加载完成并提取文本
    person_name = WebDriverWait(browser, 20).until(
        EC.visibility_of_element_located((By.XPATH, '//h1[contains(@class, "notice-name")]'))
    ).text
    
    print(f"人员姓名:{person_name}")
finally:
    browser.close()

说明:

  • 显式等待通过WebDriverWait配合条件判断,确保元素可交互或可见后再执行操作,比固定time.sleep()更稳定高效
  • 如果上述姓名元素的XPath定位失效,可通过浏览器开发者工具查看详情页中姓名元素的实际属性(如class、id),调整定位表达式

内容的提问来源于stack exchange,提问作者Giampaolo Levorato

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 14:42:48