【问题标题】:Python requests.get() not showing all HTMLPython requests.get() 未显示所有 HTML
【发布时间】:2020-03-18 14:18:06
【问题描述】:

我希望从Easy Allies reviews 中抓取一些信息用于个人项目,使用:

  • Python3
  • 请求
  • BS4(美汤)

我想抓取他们最近审查过的游戏的名称,这些名称在浏览器检查工具中很容易找到,但在此 Python 代码返回的页面源代码中不存在:

import requests
from bs4 import BeautifulSoup

page = requests.get("http://www.easyallies.com/#!/reviews")
soup = BeautifulSoup(page.text, 'html.parser')

print(soup.prettify())

我如何访问这些数据?

【问题讨论】:

    标签: python html beautifulsoup python-requests


    【解决方案1】:

    请注意,当您打开该 url 时,它会调用端点 https://www.easyallies.com/api/review/get 来获取评论。

    以这段代码为例,根据需要解析JSON结果。

    import requests
    from bs4 import BeautifulSoup
    
    data = { 'method': 'review', 'action': 'get', 'data[start]': 0, 'data[limit]': 10 }
    reviews = requests.post("https://www.easyallies.com/api/review/get", data=data)
    
    print (reviews.text)
    

    【讨论】:

    • 不错的答案,我会投赞成票,因为我没有遵循该网站的请求。只是直接检查元素。
    【解决方案2】:
    from selenium import webdriver
    import time
    from bs4 import BeautifulSoup
    
    browser = webdriver.Firefox()
    
    url = 'https://www.easyallies.com/#!/reviews'
    sada = browser.get(url)
    time.sleep(3)
    source = browser.page_source
    soup = BeautifulSoup(source, 'html.parser')
    
    for item in soup.findAll('div', attrs={'class': 'name'}):
        print(item.text)
    

    【讨论】:

      猜你喜欢
      • 2017-01-15
      • 2021-05-26
      • 1970-01-01
      • 2019-05-14
      • 2014-09-15
      • 1970-01-01
      • 2022-01-04
      • 2021-12-06
      • 1970-01-01
      相关资源
      最近更新 更多