实际上,url 是由 javascript 动态加载的,这就是为什么只有 bs4 不能抓取内容的原因。所以我将硒与bs4一起使用。
这是最小的工作解决方案:
代码:
from bs4 import BeautifulSoup
import time
from selenium import webdriver
driver = webdriver.Chrome('chromedriver.exe')
driver.maximize_window()
time.sleep(8)
url = 'https://play.google.com/store/apps/details?id=com.google.android.googlequicksearchbox&hl=en'
driver.get(url)
time.sleep(10)
soup = BeautifulSoup(driver.page_source, 'lxml')
reviews = soup.find_all('div', class_="d15Mdf bAhLNe")
for review in reviews:
all_reviews = review.select_one('span[jsname="bN97Pc"]').get_text()
print('all_reviews:' + all_reviews, sep="\n",end ="\n\n")
driver.close()
输出:
all_reviews:Since the latest update, on my Pixel2, Google search no longer works. It only shows my history - it no longer shows suggestions as I type, and when I'm finished typing and hit search, there's just a blank white screen - no error notification, no
progress bar, nothing. I don't want to have to go to C...Full Review
all_reviews:Endlessly frustrating when I get alerts for news articles I'm interested in, but opening them from the alerts doesn't take me right to the article, and usually
it's either nowhere to be found, or buried several pages into the newsfeed. I get it,
you want me to endlessly scroll through everything. St...Full Review
all_reviews:It's hard enough using a cell phone when you're my age, 66 years old. Take that and then try to learn apps and that is an obstacle in itself. Now I'm suffering
from a problem with Google app which I've always depended on. Recently when I go to search, the screen goes back to the home screen and a gr...Full Review
all_reviews:Bug in the recent update: I can no longer make Google searches unless I use the voice search. No error message or anything, the page just doesn't load at all. I would be happy to provide screenshots and further information!