我的问题是如何做与前一个问题相同的事情,但在Scrapy 0.14中.
基本上,我有GUI,它采用域,关键字,标签名称等参数,我想创建一个通用的蜘蛛来抓取那些域中的那些关键字.我通过覆盖蜘蛛管理器类或动态创建蜘蛛来阅读使用旧版scrapy的冲突内容.首选哪种方法,如何实施和调用正确的解决方案?提前致谢.
这是我想要通用的代码.它还使用BeautifulSoup.我把它配对了所以希望没有删除任何关键的理解它.
class MySpider(CrawlSpider):
name = 'MySpider'
allowed_domains = ['somedomain.com', 'sub.somedomain.com']
start_urls = ['http://www.somedomain.com']
rules = (
Rule(SgmlLinkExtractor(allow=('/pages/', ), deny=('', ))),
Rule(SgmlLinkExtractor(allow=('/2012/03/')), callback='parse_item'),
)
def parse_item(self, response):
contentTags = []
soup = BeautifulSoup(response.body)
contentTags = soup.findAll('p', itemprop="myProp")
for contentTag in contentTags:
matchedResult = re.search('Keyword1|Keyword2', contentTag.text)
if matchedResult:
print('URL Found: ' + response.url)
pass
Run Code Online (Sandbox Code Playgroud)