V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
TaEx
V2EX  ›  Python

新手求解 pyspider 的返回问题

  •  
  •   TaEx · 2020-01-10 18:34:56 +08:00 · 1390 次点击
    这是一个创建于 1732 天前的主题,其中的信息可能已经有所发展或是发生改变。
    仅仅是想走一下爬取链接的流程,过程非常之简单.代码如下, 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,
    }
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   4328 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 05:34 · PVG 13:34 · LAX 22:34 · JFK 01:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.