gpt4 book ai didi

python - 为什么我没有输出?

转载 作者:太空宇宙 更新时间:2023-11-04 04:05:05 26 4
gpt4 key购买 nike

我真的有一个非常简单的问题 - 为什么我没有得到输出?这是网站:https://riven.market/list/PC/Veiled .我认为问题是类名中的空格,但事实证明这是自然的,不会引起任何问题。如果您有任何问题,请在评论中告诉我

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(" ", ""))

最佳答案

这是我的解决方法,即查找查询将请求发送到的实际 URL。您可以通过右键单击-> inspect element -> network -> Find the get request

enter image description here

import requests
from bs4 import BeautifulSoup

# instead of sending to this
main = requests.get("https://riven.market/list/PC/Veiled")

ajax_url = "https://riven.market/_modules/riven/showrivens.php?baseurl=Lw==&platform=PC&limit=25&recency=-1&veiled=true&onlinefirst=true&polarity=all&rank=all&mastery=16&weapon=Any&stats=Any&neg=all&price=99999&rerolls=-1&sort=time&direction=ASC&page=1&time=1565851905857"
re = requests.get(ajax_url)
c = re.content

soup = BeautifulSoup(c, "html.parser")
all_divs = soup.find_all("div", class_ ="attribute weapon" )
for item in all_divs:
print(item.text)

输出


Pistol Riven Mod
new

Pistol Riven Mod
> 1 day

Pistol Riven Mod
> 1 day

Pistol Riven Mod
new

Pistol Riven Mod
new

Pistol Riven Mod
> 1 day

Pistol Riven Mod
> 1 day

Pistol Riven Mod
> 1 day

Melee Riven Mod
> 1 day

Shotgun Riven Mod
> 1 day

Pistol Riven Mod
> 1 day

Pistol Riven Mod
> 1 day

Pistol Riven Mod
> 1 week

Melee Riven Mod
> 1 week

Rifle Riven Mod
> 1 week

Shotgun Riven Mod
> 1 week

Pistol Riven Mod
> 1 week

Pistol Riven Mod
> 1 week

Pistol Riven Mod
> 1 week

Pistol Riven Mod
> 1 week

Rifle Riven Mod
> 1 week

Rifle Riven Mod
> 1 week

Melee Riven Mod
> 1 week

Shotgun Riven Mod
> 1 week

Rifle Riven Mod
> 1 week

关于python - 为什么我没有输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57505550/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com