Created
January 29, 2017 23:23
-
-
Save MostAwesomeDude/d47bb16720cb7b3a1e47dede2951eb85 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
# -*- coding: utf-8 -*- | |
import scrapy | |
from scrapy.linkextractors import LinkExtractor | |
class SiegeSpider(scrapy.Spider): | |
name = "siege" | |
def __init__(self, domain, *args, **kwargs): | |
super(SiegeSpider, self).__init__(*args, **kwargs) | |
urlBase = 'https://%s/' % domain | |
self.le = LinkExtractor(allow=[urlBase]) | |
self.allowed_domains = [domain] | |
self.start_urls = (urlBase,) | |
def parse(self, response): | |
links = self.le.extract_links(response) | |
for link in links: | |
url = link.url | |
yield {"url": url} | |
yield scrapy.Request(url, callback=self.parse) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a quick and dirty link harvester, taking a single
domain
argument and returning URLs.An easy way to prepare a siege urls.txt for a domain: