【问题标题】:how to scraping text from hidden div and class using python?如何使用 python 从隐藏的 div 和类中抓取文本?
【发布时间】:2016-11-20 20:50:35
【问题描述】:

我正在编写一个用于从该网页上抓取视频标题的脚本 "https://www.google.com.eg/trends/hotvideos" 但问题是标题隐藏在 html 源页面上,但如果我使用检查器查找它,我可以看到它

这是我的代码,它与它配合得很好 ("class":"wrap") 但是当我将它与隐藏的“class”:“hotvideos-single-trend-title-container”一起使用时,它并没有给我任何输出

#import urllib2
from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen('https://www.google.com.eg/trends/hotvideos').read()
soup = BeautifulSoup(html)
print (soup.findAll('div',{"class":"hotvideos-single-trend-title-container"}))
#wrap

【问题讨论】:

    标签: python python-2.7 python-3.x web-scraping beautifulsoup


    【解决方案1】:

    该页面是使用 Javascript 生成/填充的。

    BeautifulSoup 在这里帮不了你,你需要一个支持 Javascript 生成的 HTML 页面的库,请参阅此处以获取 list 或查看 Selenium

    【讨论】:

      猜你喜欢
      • 2016-08-26
      • 2019-05-16
      • 1970-01-01
      • 1970-01-01
      • 2017-02-20
      • 1970-01-01
      • 1970-01-01
      • 2021-10-07
      • 2018-09-22
      相关资源
      最近更新 更多