Created
August 26, 2014 00:47
-
-
Save danlamanna/773b80e6b5ff4d9d9757 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from scrapy.selector import HtmlXPathSelector | |
| from scrapy.contrib.spiders import CrawlSpider, Rule | |
| from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor | |
| from scrapy.item import Item, Field | |
| class LinkItem(Item): | |
| url = Field() | |
| referer = Field() | |
| status = Field() | |
| class Spider(CrawlSpider): | |
| name = "ua_spider" | |
| allowed_domains = ["albany.edu"] | |
| start_urls = ["http://albany.edu", ] | |
| handle_httpstatus_list = [404] | |
| rules = (Rule(SgmlLinkExtractor(), callback='parse_item', follow=True),) | |
| def parse_item(self, response): | |
| if response.status == 404: | |
| item = LinkItem() | |
| item['url'] = response.url | |
| item['referer'] = response.request.headers.get('Referer') | |
| item['status'] = response.status | |
| return item |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment