【问题标题】:HTML content requested via requests is not same as that of browser通过 requests 请求的 HTML 内容与浏览器不同
【发布时间】:2016-11-18 23:06:25
【问题描述】:

我正在尝试使用 python beautifulsoup 库从网站 html 中提取一些元素。问题是响应中的 HTML 与我在浏览器上看到的不同。代码如下:

import requests
from bs4 import BeautifulSoup
import pandas as pd

url = 'https://www.nutritionix.com/brands/restaurant'

resp = requests.get(url,verify=True)
soup = BeautifulSoup(resp.content)

我曾尝试使用 urllib 库并使用浏览器代理参数,但它不起作用。

关于如何解决此问题的任何建议?

【问题讨论】:

    标签: python-3.x web-scraping


    【解决方案1】:

    页面由javascript生成。

    尝试使用 firebug 或 google dev 工具。 enter image description here

    你想要的数据实际上来自 https://d1gvlspmcma3iu.cloudfront.net/brands-restaurant.json.gz

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-11
    • 1970-01-01
    • 1970-01-01
    • 2021-03-09
    • 1970-01-01
    • 2017-03-20
    相关资源
    最近更新 更多