最近一直在学习python,学习完了基本语法就练习了一个爬虫demo,下面总结下。

  

  主要逻辑是 

  1)初始化url管理器,也就是将rooturl加入到url管理器中

  2)在url管理器中得到新的new_url

  3)根据新new_url得到它的内容html_cont  (工具 urllib.request.urlopen(url))

  4)解析这个新页面的内容html_cont并得到新的子url,并保存解析内容结果  (利用BeautifulSoup工具)

  5)将新得到的子url保存到url管理器

  6)迭代2-5步骤,知道输出某个阈值的数量即可停止

  7)输出爬去的结果

  注意编码问题,一致为UTF-8 --   .decode('UTF-8')

  

BeautifulSoup工具的安装方式:进入Python3.x\Script下 输入指令 pip install beautifulsoup4

主页面spider_main.py:

  

'''
Created on -- @author: rongyu
'''
from bike_spider import url_manager, html_downloader, html_parser, html_outputer class SpiderMain(object): def __init__(self):
self.urls = url_manager.UrlManager()
self.downloader = html_downloader.HtmlDownloader()
self.parser = html_parser.HtmlParser()
self.outputer = html_outputer.HtmlOutputer() def craw(self, root_url):
count =
self.urls.add_new_url(root_url)
while self.urls.has_new_url():
try:
new_url = self.urls.get_new_url()
print ('craw %d:%s'%(count,new_url))
html_cont = self.downloader.download(new_url)
new_urls,new_data = self.parser.parse(new_url,html_cont)
self.urls.add_new_urls(new_urls)
self.outputer.collect_data(new_data) if count == :
break count = count +
except:
print('craw failed') self.outputer.output_html() #主程序入口 if __name__=="__main__":
root_url = "http://baike.baidu.com/view/21087.htm"
obj_spider = SpiderMain()
obj_spider.craw(root_url)    #根据url开始爬取

url管理器页面UrlManager.py

'''
Created on -- @author: rongyu
''' class UrlManager(object):
def __init__(self):
self.new_urls = set()
self.old_urls = set() def add_new_url(self,url):
if url is None:
return
if url not in self.new_urls and url not in self.old_urls:
self.new_urls.add(url) def has_new_url(self):
return len(self.new_urls) != def get_new_url(self):
new_url = self.new_urls.pop()
self.old_urls.add(new_url)
return new_url def add_new_urls(self,urls):
if urls is None or len(urls) == :
return
for url in urls:
self.add_new_url(url)

下载器页面 HtmlDownloader.py

import urllib.request

class HtmlDownloader(object):

    def download(self,url):
if url is None:
return None response = urllib.request.urlopen(url) return response.read().decode('UTF-8')

解析器页面HtmlParser.py

from bs4 import BeautifulSoup
import re
import urllib.parse class HtmlParser(object): def _get_new_urls(self, page_url, soup):
new_urls = set()
#/view/.htm
links = soup.find_all('a',href=re.compile(r"/view/\d+\.htm"))
for link in links:
new_url = link['href']
new_full_url = urllib.parse.urljoin(page_url,new_url)
new_urls.add(new_full_url)
return new_urls def _get_new_data(self, page_url, soup):
res_data = {} #url
res_data['url'] = page_url #<dd class="lemmaWgt-lemmaTitle-title"> <h1>Python</h1>
title_node = soup.find('dd',class_="lemmaWgt-lemmaTitle-title").find("h1")
res_data['title'] = title_node.get_text() #<div class="lemma-summary" label-module="lemmaSummary">
summary_node = soup.find('div',class_="lemma-summary")
res_data['summary'] = summary_node.get_text() return res_data def parse(self,page_url,html_cont):
if page_url is None or html_cont is None:
return soup = BeautifulSoup(html_cont,'html.parser',from_encoding='UTF-8')
new_urls = self._get_new_urls(page_url,soup)
new_data = self._get_new_data(page_url,soup)
return new_urls,new_data

输出器的代码HtmlOutputer.py

class HtmlOutputer(object):
def __init__(self):
self.datas = [] def collect_data(self,data):
if data is None:
#print("collect_data -data is none!")
return self.datas.append(data)
#print(self.datas) def output_html(self):
fout = open('output.html','w') fout.write("<html>")
fout.write("<body>")
fout.write("<table>")
for data in self.datas:
fout.write("<tr>")
fout.write("<td>%s</td>"%data['url'].encode('UTF-8'))
fout.write("<td>%s</td>"%data['title'].encode('UTF-8'))
fout.write("<td>%s</td>"%data['summary'].encode('UTF-8'))
fout.write("</tr>")
fout.write("</table>")
fout.write("</body>")
fout.write("</html>")

实验结果:

控制台输出

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkoAAAEBCAIAAAAINh38AAAgAElEQVR4nO2d7a9cxX3H959pG2wiFSS/ue8iVCsKTZRIDQZMYaOQTVxSUIFCkyqhEcp1miZiU9JAw5MJChRdLIhEbuUUTElLRYpiixTHwMYiFjGNqQ03WBiDI52+2N2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bIqFlJJR4pu/27a8RW8LrBSZCRvUGBz2hJStT/XHWAC8pYR2JwCADQF8gYAAC0EeQMAgBaCvAEAQAtB3gAAoIUgbwAA0EKQNwAAaCHIW3uo9SfesDBStT/XHVYc5K3QrFLiLVTy2BOheneuzV5khYQkQs4D09JgefxUZypZk8TYBU6iNidIbr51+7m22U5de1Itfsgu1SaP8QXLx6rL20CxedTCA+loww8703kn4oGdqZtv3X5ueRPNYE+qxVfT0atTd3wBZCRvoo1kKjvTYLiy5St2pk7VsDP193ouC2/8EFmvOdqZSvIWa33g/V97vNAkKtIWAztTqEsu8qbZSI5/t2g702C4LG/YmRb2bMwxTxHBzjRYr8XYmYrh0lbL3jlW9Ap7Um1KHTXVrje+qq4LrAiZyFt2dqYV4R71/Kj0cOxMpylPln5vynXZzNHO1A9v1p5UUTw1XIpYY3xhiANFUSytvKl2l03ZmVaEezQnb+79LWbdJv6DSexMg8VZVTvTsFv9bPakWvyIdKzIyBvUJRN5c74Zc99ai0+5k//Pw840FI6dqVF+7EwL8Ta6HHamWrjWn+vak2rxg+lgZwrNkIu8FZnZmer2j4U//MrCjJf7h2cMvDzcKYAfjp3pdOWxfoOdqUf9ft6EPakWP5COdF3qja/gdYGVIiN5gwI705aAnSlAepC3jMDOFACgKZA3AABoIcgbAAC0kMTytgUAADAHkDcAAGghyBsAALQQ5A0AAFpIpvL2zJi5NwAAALSRHOUNbQMAgBnJTt7QNgAAmJ285A1tAwCARshL3rZQOAAAaIL/B0jkEIO83A06AAAAAElFTkSuQmCC" alt="" />

Python:的web爬虫实现及原理(BeautifulSoup工具)的更多相关文章

  1. python多进程web爬虫-提升性能利器

    背景介绍: 小爬我最近给部门开发了一系列OA的爬虫工具,从selenium前端模拟进化到纯requests后台post请求爬取,效率逐步提升.刚开始能维持在0.5秒/笔.可惜当数据超过2000笔后,爬 ...

  2. 第三百三十六节,web爬虫讲解2—urllib库中使用xpath表达式—BeautifulSoup基础

    第三百三十六节,web爬虫讲解2—urllib库中使用xpath表达式—BeautifulSoup基础 在urllib中,我们一样可以使用xpath表达式进行信息提取,此时,你需要首先安装lxml模块 ...

  3. Python Web框架 tornado 异步原理

    Python Web框架 tornado 异步原理 参考:http://www.jb51.net/article/64747.htm 待整理

  4. Python动态网页爬虫-----动态网页真实地址破解原理

    参考链接:Python动态网页爬虫-----动态网页真实地址破解原理

  5. python简单页面爬虫入门 BeautifulSoup实现

    本文可快速搭建爬虫环境,并实现简单页面解析 1.安装 python 下载地址:https://www.python.org/downloads/ 选择对应版本,常用版本有2.7.3.4 安装后,将安装 ...

  6. Python爬虫从入门到进阶(1)之Python概述及爬虫入门

    一.Python 概述 1.计算机语言概述 (1).语言:交流的工具,沟通的媒介 (2).计算机语言:人跟计算机交流的工具 (3).Python是计算机语言的一种 2.Python编程语言 代码:人类 ...

  7. 【网络爬虫】【python】网络爬虫(四):scrapy爬虫框架(架构、win/linux安装、文件结构)

    scrapy框架的学习,目前个人觉得比较详尽的资料主要有两个: 1.官方教程文档.scrapy的github wiki: 2.一个很好的scrapy中文文档:http://scrapy-chs.rea ...

  8. Python学习网络爬虫--转

    原文地址:https://github.com/lining0806/PythonSpiderNotes Python学习网络爬虫主要分3个大的版块:抓取,分析,存储 另外,比较常用的爬虫框架Scra ...

  9. 用Python写网络爬虫 第二版

    书籍介绍 书名:用 Python 写网络爬虫(第2版) 内容简介:本书包括网络爬虫的定义以及如何爬取网站,如何使用几种库从网页中抽取数据,如何通过缓存结果避免重复下载的问题,如何通过并行下载来加速数据 ...

随机推荐

  1. ubuntu下配置JDK,Eclipse,android开发环境

    前言:由于我的电脑是64位的,所以下面使用的jdk ; eclipse : 包括我安装的 ubuntu12.0.4LTS 都是64位的:如果你是32位请下载32位的系统以及jdk,eclipse等软件 ...

  2. hadoop 通过distcp进行并行复制

    通过distcp进行并行复制 前面的HDFS访问模型都集中于单线程的访问.例如通过指定文件通配,我们可以对一部分文件进行处理,但是为了高效,对这些文件的并行处理需要新写一个程序.Hadoop有一个叫d ...

  3. Netty源码分析 (十)----- 拆包器之LineBasedFrameDecoder

    Netty 自带多个粘包拆包解码器.今天介绍 LineBasedFrameDecoder,换行符解码器. 行拆包器 下面,以一个具体的例子来看看业netty自带的拆包器是如何来拆包的 这个类叫做 Li ...

  4. 睡梦中被拉起来执行Spring事务

    梦中惊醒 在Tomcat的线程池里,有这样一个线程,自打出生后,从来不去干活儿,有好多次走出线程池“这座大山”去看世界的机会,都被他拱手让给了弟兄们. 弟兄们给他取了个名字叫二师兄.没错,好吃懒做,饱 ...

  5. php根据经纬度排序,根据经纬度筛选距离段

    SQL 语句:select location.* from (select *,round(6378.138*2*asin(sqrt(pow(sin( (36.668530*pi()/180-px_l ...

  6. jenkins之插件下载方法

    jenkins插件下载方法有两种,在线下载和离线下载方式 在线下载 就是在安装好了jenkins之后,进入jenkins的插件管理页面,搜索想要的插件,点击安装即可 例如:安装git插件 问题:有时候 ...

  7. 第六届蓝桥杯java b组第四题

    第四题 两个整数做除法,有时会产生循环小数,其循环部分称为:循环节. 比如,11/13=6=>0.846153846153….. 其循环节为[846153] 共有6位. 下面的方法,可以求出循环 ...

  8. 浅谈Spring的事务隔离级别与传播性

    浅谈Spring的事务隔离级别与传播性 这篇文章以一个问题开始,如果你知道答案的话就可以跳过不看啦@(o・ェ・)@ Q:在一个批量任务执行的过程中,调用多个子任务时,如果有一些子任务发生异常,只是回滚 ...

  9. SPSS基础学习方差分析—单因素分析

    为什么要进行方差分析? 单样本.两样本t检验其最终目的都是分析两组数据间是否存在显著性差异,但如果要分析多组数据间是否存在显著性差异就很困难,因此用方差分析解决这个问题:举例:t检验可以分析一个班男女 ...

  10. Airflow自定义插件, 使用datax抽数

    Airflow之所以受欢迎的一个重要因素就是它的插件机制.Python成熟类库可以很方便的引入各种插件.在我们实际工作中,必然会遇到官方的一些插件不足够满足需求的时候.这时候,我们可以编写自己的插件. ...