创建爬虫-----爬虫异常处理:
2017-06-30 14:30
197 查看
爬虫异常处理:
from urllib.request import urlopen from urllib.error import HTTPError,URLError from bs4 import BeautifulSoup def getTitle(url): try: html=urlopen(url) except(HTTPError,URLError) as e: return None try: bsObj=BeautifulSoup(html.read()) title=bsObj.body.h1 except AttributeError as e: return None return title title=getTitle("http://www.pythonscraping.com/pages/pages1.html") if title==None: print("title could not be found") else: print(title)
相关文章推荐
- javascript异常:”automation服务器不能创建对象“ 处理
- SilverLight中创建和处理异常 (转)
- 零基础写python爬虫之HTTP异常处理
- Python爬虫入门五之URLError异常处理
- 在自己的数据库里创建内置表来处理异常(译)
- Python爬虫之URLError异常处理
- php异常处理—创建自定义的异常处理器
- HBase创建快照(snapshot)出现异常的处理方法
- 玩转python爬虫之URLError异常处理
- 在WM下,获得当前路径处理和解决异常“Control.Invoke 必须用于与在独立线程上创建的控件交互。”
- 第二十四章 异常和错误处理 4创建异常类的成员函数
- 使用jshortcut创建程序快捷方式发生异常的处理
- python 爬虫(2)异常的处理和HTTP状态码的分类
- .NET(C#):Emit创建异常处理的方法
- 创建xhr时异常处理-Ajax之六
- win32创建异常捕获处理
- Java基础之IO流,创建文件并写入内容与IO异常的标准处理方法
- Android学习中ADT创建工程后出现appcompat_V7包和自定义包异常处理方法(文章转移)
- Python爬虫入门五之URLError异常处理