我嘗試了很多不同的答案,但沒有任何效果。
我試圖洗掉 Play 商店網站上的所有評論,發現 `class_ = "d15Mdf bAhLNe"` 是我想要的容器,但我得到一個空串列。
當我嘗試soup.find_all({class : d15Mdf bAhLNe})組合時也是如此。X
問題是,當我列印湯時,我捕獲了 HTML 檔案。我缺少什么?
from bs4 import BeautifulSoup
import requests
html_text = requests.get('https://play.google.com/store/apps/details?id=com.google.android.googlequicksearchbox&hl=en').text
soup = BeautifulSoup(html_text, 'lxml')
reviews = soup.find_all('div', class_="d15Mdf bAhLNe")
print(reviews)
``
uj5u.com熱心網友回復:
如果你列印出來soup代替reviews,你會看到你得到的 html 內容和直播網站上的 html 內容是不一樣的。因為您不是瀏覽器,所以動態創建內容的腳本沒有發揮作用。在此處查看更詳細的答案:![BeautifulSoup find_all 函式回傳一個空串列 []](https://img.uj5u.com/2021/11/10/cdd52e18ac344f6aa6f89f84102166fd.png)
我建議你看看這個答案這里
使用 Selenium 的快速示例
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
# Config Change depending on your needs
options = Options()
options.binary_location = r"binary_path"
browser = webdriver.Firefox(options=options, executable_path="driver_path")
# Get the data
url = 'https://play.google.com/store/apps/details?id=com.google.android.googlequicksearchbox&hl=en'
browser.get(url)
res = browser.find_elements(By.XPATH, '//div[@]')
print(res)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/354845.html
上一篇:Beautifulsoupwebscraping-從<a>標簽中提取值
下一篇:(C語言篇)三子棋的實作
