我试图从 eBay.com 获取商品的价格,但由于某种原因我无法获取。
price_BeautifulSoup = bs.find("span", {"id": "prcIsum"}).text
# What the console prints: "<class 'bs4.BeautifulSoup'>"
我尝试过的:
- 我尝试过用谷歌搜索
“class 'bs4.BeautifulSoup'”
。 price_BeautifulSoup = bs.find('span', attrs={"id": "prcIsum"}).get_text().strip()
整个代码:https://pastebin.com/Vb5gd7RL
提前致谢。说真的。
最佳答案
您打印了错误的变量:
print("price_BeautifulSoup", ": ", BeautifulSoup,"\n")
你想要:
print("price_BeautifulSoup", ": ", price_BeautifulSoup ,"\n")
如果您想要单独的价格,您可以提取内容属性
bs.select_one('#prcIsum')['content']
如果您想匹配 selenium 列表输出,然后按空格分割:
print("price_selenium", ": ", price_selenium)
print("price_BeautifulSoup", ": ", price_BeautifulSoup.split(' ') ,"\n")
关于python - BeautifulSoup:无法获取文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58161241/