【发布时间】:2017-02-24 06:40:29
【问题描述】:
我正在尝试使用下面显示的代码从下一页提取阅读器 cmets。但输出 html test.html 不包含页面中的任何 cmets。如何使用 Python 获取这些信息?
from bs4 import BeautifulSoup
import urllib
import urllib.request
import urllib.parse
req =urllib.request.Request('http://www.theglobeandmail.com/opinion/it-doesnt-matter-who-won-the-debate-america-has-already-lost/article32314064/comments/')
response = urllib.request.urlopen(req)
the_page = response.read()
soup = BeautifulSoup(the_page, 'html.parser')
f = open('test.html', 'w')
f.write(soup.prettify())
f.close()
谢谢!
【问题讨论】:
-
cmets最有可能是用js检索的。您可以使用包含浏览器 + js 运行时(pahtomjs 等)的抓取库,也可以尝试找出用于提取 cmets 的 api 是什么并直接使用它。
标签: python web-scraping urllib