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

不使用Selenium爬取欧盟RASFF页面无法提取目标数据如何解决

解决方案

问题根因

你当前请求拿到的是网站的基础框架页,服务器识别到非浏览器的爬虫请求后,未返回实际业务数据。你在浏览器F12中看到的完整内容,是浏览器携带合法身份标识请求后拿到的完整页面/接口数据渲染后的结果。

方案1:补全请求头爬取HTML页面

给requests请求补充完整的浏览器请求头,模拟普通用户访问,即可拿到带目标数据的完整页面:

from bs4 import BeautifulSoup
import requests
import pandas as pd

# 替换为你自己浏览器的User-Agent,可在浏览器F12控制台网络tab随便找个请求查看
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
    "Accept-Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2",
    "Referer": "https://webgate.ec.europa.eu/rasff-window/screen/search"
}

url = 'https://webgate.ec.europa.eu/rasff-window/screen/notification/486901'
res = requests.get(url, headers=headers)
soup = BeautifulSoup(res.text, 'html.parser')

# 接下来按照元素的class、id定位你需要的Product、Product category等字段即可

方案2:直接调用官方数据接口(更适合批量爬取)

该平台的通知数据有公开的后端接口,直接返回JSON格式数据,无需解析HTML,稳定性和效率更高,尤其适合上千条批量爬取的场景:
接口格式为https://webgate.ec.europa.eu/rasff-window/backend/public/notification/view/{通知ID}/,你要的486901通知对应接口就是该格式替换ID后的地址,示例代码如下:

import requests
import pandas as pd

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36",
    "Accept": "application/json, text/plain, */*"
}

notification_id = 486901
api_url = f"https://webgate.ec.europa.eu/rasff-window/backend/public/notification/view/{notification_id}/"
res = requests.get(api_url, headers=headers)
data = res.json()

# 直接从JSON中提取需要的字段
result = {
    "Product": data.get("product"),
    "Product category": data.get("productCategory"),
    "reference": data.get("reference"),
    "subject": data.get("subject")
}

# 转成DataFrame
df = pd.DataFrame([result])

批量爬取注意事项

  • 每次请求间隔1-2秒,避免请求频率过高触发IP封禁
  • 可准备多个备用User-Agent轮流使用,降低被识别为爬虫的概率

内容的提问来源于stack exchange,提问作者Dawn.Sahil

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.10 16:36:03