import requestsfrom bs4 import BeautifulSoupimport refrom 爬虫基础 import url_managerroot_manger = httpwwwcrazyantneturls = url_managerUrlManagerurlsadd_new_urlroot_urlwhile urlshas_new_url curr_url =
- 在导入 url_manager 模块时,应该使用 from url_manager import UrlManager 而不是 import url_manager。
- 在使用 UrlManager 类时,应该实例化一个对象,而不是直接使用类名。因此应该将 urls = url_manager.UrlManager 改为 urls = UrlManager()。
- 在添加新的链接时,应该使用实例方法 add_new_urls() 而不是 add_new_url()。因此应该将 urls.add_new_url('root_url') 改为 urls.add_new_urls(['root_url'])。
- 在解析完一个页面后,应该将页面中的所有链接添加到待爬取列表中。因此应该将 links = soup.find_all('a') 后面的代码块缩进,使其成为 for 循环的一部分。
- 在判断链接是否符合要求时,应该使用 re.match() 而不是 re.math()。因此应该将 if re.math(pattern, href) 改为 if re.match(pattern, href)。
- 在判断链接是否已经爬取时,应该使用 urls.has_new_url(href) 而不是 urls.has_new_url()。因此应该将 if urls.has_new_url(href) 改为 if urls.has_new_url(href) is False。
原文地址: http://www.cveoy.top/t/topic/8th 著作权归作者所有。请勿转载和采集!