【发布时间】:2019-10-27 18:58:47
【问题描述】:
问的问题很简单,但对我来说,它不起作用,我不知道!
我想用 BeautifulSoup 从这个页面 https://www.brewersfriend.com/homebrew/recipe/view/16367/southern-tier-pumking-clone 刮掉评分啤酒,但它不起作用。
这是我的代码:
import requests
import bs4
from bs4 import BeautifulSoup
url = 'https://www.brewersfriend.com/homebrew/recipe/view/16367/southern-tier-pumking-clone'
test_html = requests.get(url).text
soup = BeautifulSoup(test_html, "lxml")
rating = soup.findAll("span", class_="ratingValue")
rating
当我完成时,它不起作用,但如果我对另一个页面做同样的事情......我不知道。有人可以帮助我吗?评分结果为 4.58
谢谢大家!
【问题讨论】:
-
可能是因为您收到了 403 禁止响应。当你在做这种事情时,一步一步地进行,每一步之后确保它有效。
-
带有 ratingValue 的跨度不在类上,在属性 ITEMPROP 上
-
我什至没有检查我的错:),我检查的第一件事是获取请求,它返回 403
-
你在做什么?选择对其他读者也有帮助的答案。
标签: python beautifulsoup screen-scraping scrape