我对 Scrapy 很陌生。在这里我的蜘蛛要爬twistedweb。
class TwistedWebSpider(BaseSpider):
name = "twistedweb3"
allowed_domains = ["twistedmatrix.com"]
start_urls = [
"http://twistedmatrix.com/documents/current/web/howto/",
]
rules = (
Rule(SgmlLinkExtractor(),
'parse',
follow=True,
),
)
def parse(self, response):
print response.url
filename = response.url.split("/")[-1]
filename = filename or "index.html"
open(filename, 'wb').write(response.body)
当我运行时 scrapy-ctl.py crawl twistedweb3
,它只获取。
获取index.html
内容,我尝试使用SgmlLinkExtractor
,它按我的预期提取链接,但无法遵循这些链接。
你能告诉我哪里出错了吗?
假设我想获取 css、javascript 文件。我如何实现这一目标?我的意思是获得完整的网站?