请求模块没有提供与在浏览器中使用检阅时相同的html文本

时间:2019-07-03 11:43:50

标签: html python-3.x beautifulsoup request

我想创建一个脚本来计算youtube播放列表的总时长。为了做到这一点,我用google chrome中的一个小时间图标进行检查,这样我就可以看到时间数据的存储位置。

我使用请求来获取html文本,但是它给了我完全不同的结果,并且找不到时间数据!

反正有找到这些数据吗? 我以前从未使用过请求,也从未使用过html,因此我不确定如何做到这一点。

到目前为止,这是我的代码:

from bs4 import BeautifulSoup
import requests


source = requests.get("https://www.youtube.com/watch? 
v=UO98lJQ3QGI&list=PL-osiE80TeTvipOqomVEeZ1HRrcEvtZB").text

soup = BeautifulSoup(source, "lxml")

# html tag and class that i am seeing in google chrome inspect tool 

# <span class="style-scope ytd-thumbnail-overlay-time-status-renderer" 
#aria-label="34 minuter">
#       34:26
#     </span>

for match in soup.find_all("span", class_="style-scope ytd-thumbnail- 
                            overlay-time-status-renderer"):
    time = match.text.strip()
    print(time)

0 个答案:

没有答案