【发布时间】:2014-10-07 10:45:02
【问题描述】:
其实我是 Web 和 Scrapy 的新手......所以如果我的问题是愚蠢的,请理解。
这就是我想要的,(A)http://www.seoultech.ac.kr/包括一个链接的 URL (B)ctl.seoultech.ac.kr。
(B) 的域是 (A) 的子域
我的 start_urls 是 (A),而不是 using allow_domains=(B) 的 LinkExtractor ,爬虫只提取一页 (B),并且
其次,由于页面 (B) 还包含一些带有其域的 URL,我希望它会提取 (B) 中包含的 URL,但它不起作用,只能抓取 (B)。
URL (B) 被重定向到http://ctl.seoultech.ac.kr/web/index.php,但我知道 Scrapy 自己处理它,我认为这不是问题。
以下是我的简单代码。
class SeoulTech(CrawlSpider):
name = 'seoulTech'
start_urls = ['http://www.seoultech.ac.kr/']
allowed_domains = ['seoultech.ac.kr']
rules = (
Rule(LinkExtractor(allow_domains=("ctl.seoultech.ac.kr",)), callback="parse_item", follow=True),
)
def parse_item(self, response):
itemObj = items.SeoulTechItem()
itemObj['url'] = response.url
yield itemObj # pipeline just store URL as json format
【问题讨论】:
标签: python-2.7 web-crawler scrapy-spider