【问题标题】:Python Scrapy, LinkExtracotr doesn't work on some specific url redirectingPython Scrapy,LinkExtracotr 不适用于某些特定的 url 重定向
【发布时间】: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


    【解决方案1】:

    如您所说,URL (B) 被重定向到http://ctl.seoultech.ac.kr/web/index.php。所以 LinkExtractor 肯定不会处理 URL (B) 的页面。

    【讨论】:

    • 但是,当我使用 Scrapy 搜索重定向时,它似乎默认处理重定向,当我尝试使用其他 URL 时,它处理重定向,显示重定向日志。
    • URL(B) 不是有效的 URL。它不引用任何网页。因此,当您尝试直接访问它时,HTTP 服务器肯定会将您重定向到其所谓的“索引”页面(即ctl.seoultech.ac.kr/web/index.php)。重定向由服务器完成。您的选择只是接受或不接受重定向。
    猜你喜欢
    • 2015-12-30
    • 2018-09-12
    • 2012-10-09
    • 1970-01-01
    • 2014-12-02
    • 1970-01-01
    • 1970-01-01
    • 2022-01-01
    • 1970-01-01
    相关资源
    最近更新 更多