我正在尝试从下面的URL获取文章文本、标题和文章发布日期
https://www.argusmedia.com/en/news/2214037-us-hrc-prices-rise-as-supply-remains-tight
当我尝试使用类“news container cf”刮取“article”容器时,它返回0行
#Reprex代码
url = "https://www.argusmedia.com/en/news/2214037-us-hrc-prices-rise-as-supply-remains-tight"
# Request
r1 = requests.get(url, verify=False)
r1.status_code
print(r1.status_code)
# We'll save in coverpage the cover page content
coverpage = r1.content
# Soup creation
soup1 = BeautifulSoup(coverpage, "html5lib")
# News identification
coverpage_news = soup1.find_all('article' , class_ ='news-container cf')
len(coverpage_news) ```
这是因为这是动态加载的,所以需要直接调用API
该页面运行Java脚本。
Requests
是一个http库,无法运行javascript。 为了“查看”javscript网页的HTML,您需要处理页面上的所有代码并实际呈现内容。 一种方法是使用requests_html
模块输出:
从docs
如果要搜索与两个或多个CSS类匹配的标记,应使用CSS选择器:
相关问题 更多 >
编程相关推荐