【发布时间】:2014-02-10 17:38:48
【问题描述】:
我需要实现一些爬虫来抓取一些网页(因为该网站没有开放的 API),提取信息并保存到数据库。我目前正在使用漂亮的汤来编写这样的代码:
discount_price_text = soup.select("#detail-main del.originPrice")[0].string;
discount_price = float(re.findall('[\d\.]+', discount_price_text)[0]);
我猜这样的代码很容易在网页改变时变得无效,即使是轻微的改变。 除了编写回归测试以定期运行以捕获故障之外,我应该如何编写不易受这些变化影响的爬虫?
特别是,即使原始 xpath/css 选择器不再有效,是否有任何现有的“智能抓取工具”可以进行“尽力猜测”?
【问题讨论】:
标签: python web web-scraping beautifulsoup