0
回答
scrapy请求的时候报 name 'x' is not defined 错误。求解决

代码是按照http://scrapy-chs.readthedocs.io/zh_CN/1.0/intro/tutorial.html的例子写的。用的是python3.4+scrapy1.1。

代码是这样的

import scrapy

class DmozSpider(scrapy.Spider):
    name = "dmoz"
    allowed_domains = ["dmoz.org"]
    start_urls = [
        "http://www.dmoz.org/Computers/Programming/Languages/Python/Books/",
        "http://www.dmoz.org/Computers/Programming/Languages/Python/Resources/"
    ]

    def parse(self, response):
        filename = response.url.split("/")[-2] + '.html'
        with open(filename, 'wb') as f:
            f.write(response.body)



举报
liangfei2016x
发帖于2年前 0回/592阅
顶部