V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Jan 10, 2020 · 1722 views
    This topic created in 2299 days ago, the information mentioned may be changed or developed.
    仅仅是想走一下爬取链接的流程,过程非常之简单.代码如下, 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,
    }
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5652 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 06:50 · PVG 14:50 · LAX 23:50 · JFK 02:50
    ♥ Do have faith in what you're doing.