Python爬虫小记(一)
来源:互联网 发布:文言虚词乎的用法 编辑:程序博客网 时间:2024/06/05 00:59
刚开始接触处python爬虫,为了让这件事情一直持续下去,因此用博客的方式记录下自己学习过程当中的点滴。该博客一般直接只贴代码,除非遇到特别棘手的问题。使用python 3.0 版本和PyCharm开发工具。希望自己能够坚持下去,积累的越来越多。
以下是第一个代码片段,实现爬取html中的标签内容更,很简单。其中的网址来自于《Python网络数据采集》。
from urllib.request import urlopenfrom urllib.error import HTTPErrorfrom bs4 import BeautifulSouptry: html=urlopen("http://www.pythonscraping.com/pages/page1.html")except HTTPError as e: print (e)else: if html is None: print("URL is not found") else: bsObj = BeautifulSoup(html.read(),"lxml") try: content = bsObj.find("body").div except AttributeError as e: print("Tag was not found") else: if content is None: print("badContent is None") else: print(content)
阅读全文
0 0
- Python爬虫小记(一)
- 爬虫小记(一)
- Python爬虫小记(二)
- Python爬虫小记(三)
- Python小记(一)
- python 小记(一)
- python 爬虫小记
- Python + Selenium 爬虫小记
- python爬虫小记
- Python爬虫入门小记
- python 爬虫小记之一
- Python爬虫(一)
- Python爬虫(一)
- python爬虫(一)
- Python爬虫(一)
- python爬虫(一)
- python爬虫(一)
- python爬虫(一)
- linux虚拟机上中挂载光驱报错 mount:youmustspecifythefilesystemtype
- 进程与线程的区别与联系
- java反射机制
- C#笔记(8)使应用具有管理员权限
- Lintcode二进制求和
- Python爬虫小记(一)
- 高精度非负数模板
- Java Web 会话保留技术
- Cordova 学习笔记一
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- c#从控制台输入问题
- request response session
- Ajax的ajax()和post()的使用
- 最大子串和问题