我的问题是如何做与前一个问题相同的事情,但在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) 我需要创建一个用户可配置的Web蜘蛛/爬虫,我正在考虑使用Scrapy.但是,我无法对域进行硬编码并允许使用URL正则表达式:es - 这可以在GUI中进行配置.
我如何(尽可能简单)使用Scrapy创建一个蜘蛛或一组蜘蛛,其中域和允许的URL正则表达式是可动态配置的?例如,我将配置写入文件,蜘蛛以某种方式读取它.
我需要实现一些抓取工具来抓取一些网页(因为该网站没有开放的API),提取信息并保存到数据库.我目前正在使用漂亮的汤来编写这样的代码:
discount_price_text = soup.select("#detail-main del.originPrice")[0].string;
discount_price = float(re.findall('[\d\.]+', discount_price_text)[0]);
Run Code Online (Sandbox Code Playgroud)
我想这样的代码在网页更改时很容易变得无效,甚至是轻微的.除了编写回归测试以定期运行以捕获故障之外,我应该如何编写不易受这些更改影响的scrappers?
特别是,即使原始的xpath/css选择器不再有效,是否有任何现有的"智能剪贴板"可以"尽力猜测"?