【发布时间】:2021-04-19 12:42:22
【问题描述】:
我目前正在使用 bs4 来抓取以下website。我想将视图从“Top Reactions”更改为“Latest Reactions”,但唯一的方法是添加“selected”作为“Latest Reactions”周围的标签类之一。但是,在这样做之后,html 代码不会更改,并且仍然显示“热门反应”。有没有办法使用 bs4 解决这个问题?
url = "https://finance.yahoo.com/quote/{0}/community?p={0}".format(ticker)
page = urlopen(url)
html = page.read().decode("utf-8")
soup = BeautifulSoup(html, "html.parser")
latest_button = soup.find('li', {'class' : 'H(44px)'})
latest_button['class'] = latest_button['class'] + 'selected'
comments = soup.findAll("li", {"class": "comment"})
for comment in comments: # Goes through the latest n messages
post = {
}
post["content"] = comment.find("div", {"class": "C($c-fuji-grey-l)"}).text
print(post)
【问题讨论】:
-
Beautifulsoup 无法更新您应该使用的网站内容
selenium -
@AminGuermazi 有没有办法在没有浏览器的情况下运行 selenium,这样就可以在云端运行?
-
我认为 selenium 不能在没有浏览器的情况下工作
标签: python web-scraping beautifulsoup