新手求解 pyspider 的返回问题

2020-01-10 18:34:56 +08:00
 TaEx
仅仅是想走一下爬取链接的流程,过程非常之简单.代码如下, check 时 follow 已经能得到该链接了, 为什么返回的 results 为空呢?求解, 在此谢过啦


from pyspider.libs.base_handler import *

class Handler(BaseHandler):
crawl_config = {
}

def __init__(self):
self.count = 0
@every(minutes=24 * 60)
def on_start(self):
self.crawl('http://os.cs.tsinghua.edu.cn/oscourse/OS2015#A.2Bi.2F56C4uyTkk-', callback=self.index_page)

@config(age=10 * 24 * 60 * 60)
def index_page(self, response):
for each in response.doc('a[href^="http://os.cs.tsinghua.edu.cn/oscourse/OS2015/lecture"]').items():
self.crawl(each.attr.href+"?action=AttachFile", headers={'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}, callback=self.lecture_page)

@config(age=10 * 24 * 60 * 60)
def lecture_page(self, response):
for each in response.doc('a[href$=".pptx"]').items():
self.crawl(each.attr.href, headers={'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}, callback=self.detail_page)

@config(priority=20)
def detail_page(self, response):
self.count = self.count+1
return {
"url": response.url,
"title": self.count,
"content": response.url,
}
1391 次点击
所在节点    Python
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/636947

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX