【问题标题】:Having problem while scraping playstore reviews抓取 Playstore 评论时遇到问题
【发布时间】:2021-07-19 14:02:41
【问题描述】:

当我检查 HTML 元素时,从 Play 商店 span tag 获取评论,类名为 X43Kjb。但是,我得到一个空字符串。

url = "https://play.google.com/store/apps/details?id=com.cashkaro&showAllReviews=true"
import requests                
rom bs4 import BeautifulSoup                  
response = requests.get(url)                          
doc = BeautifulSoup(page_contents, 'html.parser')                      
span_tags = doc.find_all('span', {'class' : "X43Kjb"})                         
len(span_tags)

输出:0

【问题讨论】:

    标签: python python-3.x web-scraping beautifulsoup python-requests


    【解决方案1】:

    Playstore 使用javascript 加载数据。所以,我认为你不能只使用requestsBeautifulSoup 来抓取它。但是,如果您尝试深入分析,那么您可能会发现仅使用这些库的数据。

    我找到了this 的答案,它可能适合您,也可能不适合您,但请尝试一下。这也是您必须深入分析网站 html 代码以在其中查找数据的示例。

    import urllib,json,requests
    from bs4 import BeautifulSoup
    URL='http://play.google.com/store/apps/details?id=com.delta.mobile.android&hl=en_US&showAllReviews=true'
    USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:65.0) Gecko/20100101 Firefox/65.0"
    headers = {"user-agent": USER_AGENT}
    resp = requests.get(URL, headers=headers)
    soup = BeautifulSoup(resp.content, "html.parser")
    #print(soup.prettify())
    a=[]
    txt = soup.find_all('script',text=True)
    for i in txt:
        if("gp:" in i.text):
            a.append(i.text)
    i=a[-1]
    i=i.split(",null,\"")
    del i[0]
    for j in i:
        if('http' not in j):
            print(j[:j.index("\"")])
            print()
    

    免责声明:我没有测试过这段代码。所以,我不知道它是否有效。

    无论如何,我建议您使用selenium 从这些类型的网站中抓取数据,这些网站使用javascript 加载数据。

    【讨论】:

      猜你喜欢
      • 2020-05-22
      • 2016-08-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 2015-11-27
      • 1970-01-01
      相关资源
      最近更新 更多