我无法找到并返回 <b>
中出现的值。标签,我在阅读任何标签时都没有运气。
我不想发布一百行查看源信息,并且不确定如何正确发布链接,但如果您能够自己查看页面源,这里是网页 http://yugiohprices.com/card_price?name=Dark+Magician
我试图检索的信息 https://postimg.org/image/5fwxfqjqf/
这是我正在使用的代码
import requests
from bs4 import BeautifulSoup
r = requests.get('http://yugiohprices.com/card_price?name=Dark+Magician');
soup = BeautifulSoup(r.content, "lxml")
print soup.find('b').text
这是输出
首页 |前 100 名 |浏览卡片 |浏览集
购买统计 |关注列表 |卡定价器
卖我的卡片|价格提醒|博客 |常见问题 |设置
无论我如何更改或尝试,我都无法访问“LDK2-ENY10”文本
最佳答案
您可以看到页面需要一段时间来加载数据,数据是通过 Ajax 请求请求的,因此请求返回的内容并不是您在浏览器中看到的内容。您可以通过简单的访问http://yugiohprices.com/get_card_prices/Dark+Magician来模拟ajax请求。 ,传递时间戳:
import requests
from time import time
r = requests.get("http://yugiohprices.com/get_card_prices/Dark+Magician?_={}".format(int(time())))
print(r.content)
您将看到有关该卡的所有详细信息,因此要获得您想要的内容,只需找到以 /browse_sets 开头的 href 的 anchor ?设置:
In [1]: import requests
...: from time import time
...: from bs4 import BeautifulSoup
...:
...: r = requests.get("http://yugiohprices.com/get_card_prices/Dark+Magician?
...: _={}".format(int(time())))
...: soup = BeautifulSoup(r.content, "lxml")
...: print(soup.select_one("a[href^=/browse_sets?set]").text)
...:
Legendary Decks II
In [2]:
关于Python Beautifulsoup 访问标签中的文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39904089/