【发布时间】:2019-12-21 15:38:33
【问题描述】:
我真的有一个非常简单的问题 - 为什么我没有输出?这是网站:https://riven.market/list/PC/Veiled。我认为问题是类名中的空格,但结果是自然的,不应该引起任何问题。如果您有任何问题,请在 cmets 中告诉我
import requests
from bs4 import BeautifulSoup
r = requests.get("https://riven.market/list/PC/Veiled")
c = r.content
soup = BeautifulSoup(c, "html.parser")
all = soup.find_all("div", {"class":"riven-list" })
for item in all:
print("Name" + item.find("div", {"class": "attribute weapon"}).text.replace("\n", "").replace(" ", ""))
【问题讨论】:
-
没有
<div>类riven-list的标签 -
那个页面没有这样的div。不要使用检查器来抓取项目,因为它会误导你。仅使用“查看源代码”。
-
不知怎的还是不行
-
@Stasiek 它不起作用,因为如果您查看页面源代码,则没有带有
riven-list的<div>标签。就像Selcuk所说的,不要使用inspector对象来获取元素的ID,而是查看页面源来抓取它。
标签: python beautifulsoup python-requests