我对从globe和mail文章(http://www.theglobeandmail.com/)中删除读者评论线程很感兴趣。例如,在下面的评论页面中,我希望输出如下所示:
输出:
评论1 奥米戈什2天前 我不敢相信。。。你知道吗
评论1.1 sirencall 2天前 在篮子里。。。你知道吗
评论1.2 阿托兹先生两天前 我完全同意。我也有同样的。。。你知道吗
是的。 . . . 你知道吗
评论2 大卫两天前在桃园 我靠!我生命中剩下的40分钟。。。 . . . 你知道吗
我正在使用python3。我研究了以下python库:scrapy、urllib、paper、BeautifulSoup。问题是我从url得到的html页面不包含注释文本。下面我解释我是如何使用刮痧。你知道吗
使用scrapy,我创建了一个名为scrapnews的项目
scrapy startproject ScrapeNews(开始项目新闻)
然后我在spider中编写了以下代码。你知道吗
import scrapy
class NewsSpider(scrapy.Spider):
name = 'news'
start_urls = {
'http://www.theglobeandmail.com/opinion/it-doesnt-matter-who-won-the-debate-america-has-already-lost/article32314064/',
'http://www.theglobeandmail.com/opinion/it-doesnt-matter-who-won-the-debate-america-has-already-lost/article32314064/comments/'
}
def parse(self, response):
'''
:param response:
:return:
'''
page = response.url.split("/")[-2]
filename = 'gnm-%s.html' %page
with open(filename, 'wb') as f:
f.write(response.body)
然后我运行了以下命令,创建了gnm-注释.html. 你知道吗
scrapy crawl news
我在这个html中根本看不到注释文本或标记。当我检查网页上的评论时,我看到评论有标签:
<p class="comment">
但它不会出现在使用scrapy提取的html中。 我怀疑我没有从网上抓到正确的东西。你知道吗
有什么问题吗?我将非常感谢有关的解决方案,解释或指针。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐