【问题标题】:How to find hidden value in html on a website using python requests and BeautifulSoup如何使用 python 请求和 BeautifulSoup 在网站上的 html 中查找隐藏值
【发布时间】:2020-11-24 20:36:01
【问题描述】:

我试图弄清楚如何找到仅在单击网页上的按钮时才显示的隐藏值。我在网络日志中看不到任何发送另一个获取请求以显示隐藏值的内容。如何获取网页上的隐藏值?

这是我的代码:

product_page = self.url_session.get(
            'https://www.finishline.com/store/product/nike-mamba-fury-basketball-shoes/prod2797512',
            headers={
                'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
                'accept-encoding': 'gzip, deflate, br',
                'accept-language': 'en-US,en;q=0.9',
                'cache-control': 'max-age=0',
                'sec-fetch-dest': 'document',
                'sec-fetch-mode': 'navigate',
                'sec-fetch-user': '?1',
                'upgrade-insecure-requests': '1',
                'user-agent': user-agent
            },
            params={
                'styleId': f'{styleId}',
                'colorId': f'{colorId}'
            },
            cookies={
                '_abck': cookie # This gets a cookie
            }
        )

我试图在 html 中显示“cartCatalogRefIds”值。

【问题讨论】:

  • 需要点击页面上的什么元素才能出现cartCatalogRefIdsvalue
  • 这是“添加到包”按钮。

标签: python beautifulsoup python-requests


【解决方案1】:

你需要通过id找到元素,然后提取值:

from bs4 import BeautifulSoup
soup = BeautifulSoup(product_page.body)
value= soup.find(id='cartCatalogRefIds')['value']

你有你的价值

【讨论】:

  • 我试过了,但它什么也没返回。但是一旦我单击“添加到包”按钮,隐藏的值就会显示出来。而且我也没有看到任何与之相关的帖子或获取请求。
猜你喜欢
  • 1970-01-01
  • 2020-08-02
  • 1970-01-01
  • 1970-01-01
  • 2021-09-15
  • 2023-03-26
  • 2023-04-03
  • 2020-10-09
  • 1970-01-01
相关资源
最近更新 更多