【发布时间】:2020-06-09 03:03:25
【问题描述】:
我正在尝试使用 python 中的 Requests 和 BeautifulSoup 模块在公共网站中请求特定的数据属性。网站标签中的数据属性没有任何价值,但我想我可以使用代码的 title 部分来请求它。
import requests
from bs4 import BeautifulSoup
URL = 'https://www.oneplus.com/ca_en/oneplus-7pro?from=op7pro_header'
headers = {"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36'}
page = requests.get(URL, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser')
title = soup.find(attrs={"data-v-5b5a108c": True})
print(title)
当我使用具有值的数据属性请求父标记时,我正在寻找的标记不会出现。为什么我看不到?我是疯了还是这不是它的工作原理?
【问题讨论】:
标签: python html beautifulsoup python-requests