美丽之声:无法获得特克斯

2024-06-28 15:51:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图从eBay.com上获取物品的价格,但由于某些原因我无法获取

price_BeautifulSoup = bs.find("span", {"id": "prcIsum"}).text
# What the console prints: "<class 'bs4.BeautifulSoup'>"

我所尝试的:

  • 我试过用google "class 'bs4.BeautifulSoup'"
  • price_BeautifulSoup = bs.find('span', attrs={"id": "prcIsum"}).get_text().strip()

enter image description here

整个代码:https://pastebin.com/Vb5gd7RL

提前谢谢。说真的


Tags: textcomidbs价格find物品price
2条回答

您打印了错误的变量:

print("price_BeautifulSoup", ": ", BeautifulSoup,"\n")

你想要:

print("price_BeautifulSoup", ": ", price_BeautifulSoup ,"\n")

如果想要一个单独的价格,可以提取content属性

bs.select_one('#prcIsum')['content']

如果要匹配selenium列表输出,请按空格拆分:

print("price_selenium", ": ", price_selenium)
print("price_BeautifulSoup", ": ", price_BeautifulSoup.split(' ') ,"\n")

试试这个:

html = item.body
parsed_html = BeautifulSoup(html)
spans = parsed_html.find('span', attrs={"id": "prcIsum"})
body = spans.string
print(body)

相关问题 更多 >