我试图从一个使用bs4和请求的网站获取一些信息。
我想找一个特别的部门:
<div id="jive-comment-tabs" class="j-comment-wrapper" xmlns="http://www.w3.org/1999/html"> ..... </div>
但是,当我使用以下代码时:
import requests
from bs4 import BeautifulSoup
URL = "https://www.element14.com/community/community/design-challenges/in-the-air-design-challenge/blog/2014/10/26/firecracker-analyzer-index"
page = requests.get(URL)
soup = BeautifulSoup(page.content, "lxml")
print(soup.find('div', {'class': 'j-comment-wrapper'}))我得到的结果是None,而且我知道它在网页上。我在互联网上尝试了大多数的解决方案,但没有一个方案对我有帮助。有什么想法吗?
发布于 2021-10-31 06:49:40
会发生什么?
网站是动态地服务于这些部分的内容,所以你不会得到它的请求以这种方式。
交替法
尝试使用硒,它将呈现页面,您将得到结果。
from bs4 import BeautifulSoup
from selenium import webdriver
driver = webdriver.Chrome('YOUR PATH TO CHROMEDRIVER')
driver.get('https://www.element14.com/community/community/design-challenges/in-the-air-design-challenge/blog/2014/10/26/firecracker-analyzer-index')
soup=BeautifulSoup(driver.page_source, 'html.parser')
soup.find('div', {'class': 'j-comment-wrapper'})https://stackoverflow.com/questions/69783020
复制相似问题