我正在嘗試使用 bs4 和請求從網站獲取一些資訊。
網址是:https : //www.element14.com/community/community/design-challenges/in-the-air-design-challenge/blog/2014/10/26/firecracker-analyzer-index
我正在嘗試訪問特定的 div:
<div id="jive-comment-tabs" 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并且我知道它在網頁上。我嘗試了互聯網上的大多數解決方案,但沒有一個對我有幫助。有任何想法嗎?
uj5u.com熱心網友回復:
發生什么了?
網站正在動態地提供這部分內容,因此您不會以這種方式通過請求獲得它。
替代方法
嘗試使用selenium,它將呈現頁面,您將獲得結果。
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://www.uj5u.com/yidong/344491.html
