【发布时间】:2020-01-17 07:46:23
【问题描述】:
我正在抓取一个 YouTube 页面并在网上找到一个开放的程序代码。代码运行并返回正确的结果。但是,当我逐句学习代码时,我发现我在源代码中找不到该属性。我在页面源代码中搜索它,检查元素视图并将原始代码复制并粘贴到 word 中。哪里都找不到。
这是怎么发生的?
代码如下:
soup=BeautifulSoup(result.text,"lxml")
# cannot find yt-lockup-meta-info anywhere......
view_element=soup.find_all("ul",class_="yt-lockup-meta-info")
totalview=0
for objects in view_element:
view_list=obj.findChildren()
for element in view_list:
if element.string.endwith("views"):
videoviews=element.text.replace("views","").replace(",","")
totalview=totalview+int(videoviews)
print(videoviews)
print("----------------------")
print("Total_Views"+str(totalview))
我搜索的属性是“yt-lockup-meta-info”。
页面来源为here。
【问题讨论】:
标签: python html web-crawler