怎样在工商局网站做公示,wordpress 3.7,wordpress手机浏览,dz网站恢复数据库页面是随时升级的#xff0c;所以现在的链接不代表以后的链接#xff0c;但是万变不离其宗#xff0c;只要学会解析页面#xff0c;那么就能走的更远。 码云链接#xff1a;https://gitee.com/ALADL/baike_spider.git from baike_spider import url_manager,html_download…页面是随时升级的所以现在的链接不代表以后的链接但是万变不离其宗只要学会解析页面那么就能走的更远。 码云链接https://gitee.com/ALADL/baike_spider.git from baike_spider import url_manager,html_downloader, html_parser, html_outputerclass SpiderMain(object):def __init__(self):# 初始化各个对象self.urls url_manager.UrlManager()# url管理器self.downloader html_downloader.HtmlDownloader()# 下载器self.parser html_parser.HtmlParser()# 解析器self.outputer html_outputer.HtmlOutputer()# 输出器def craw(self, root_url):count 1# 将入口rooturl添加进管理器self.urls.add_new_url(root_url)# 当管理器中有了url之后我们就可以启动循环while self.urls.has_new_url():# 为了防止无效的url这里异常处理try:# 获取一个带爬取的urlnew_url self.urls.get_new_url()# 辅助打印一下当前print(craw %d:%s%(count,new_url))# 启用下载器下载页面html_cont self.downloader.download(new_url)# 调用解析器解析页面得到新的url和新的数据new_urls,new_data self.parser.paser(new_url,html_cont)# 分别处理新的url添加进url管理器self.urls.add_new_urls(new_urls)# 同时收集数据self.outputer.collect_data(new_data)# 先爬取1000个urlif count 1000:breakcount 1except:print(craw failed)# 调用outputer来处理数据self.outputer.output_html()if __name__ __main__:root_url https://baike.baidu.com/item/%E8%8B%8F%E8%BD%BC/53906#hotspotmining# main函数中复制要爬取的页面obj_spider SpiderMain()obj_spider.craw(root_url) 转载于:https://www.cnblogs.com/ALADL/p/9671690.html