网络爬虫是根据必定的规则自动的对网络信息进行抓取,为了对爬虫有更深的了解,学习爬虫前有必要先了解一下一个网页打开的完整过程,能够参考http://blog.csdn.net/saiwaifeike/article/details/8789624html
http://www.heibanke.com/lesson/crawler_ex00/
咱们用urlopen访问这个网页,而后用BeautifulSoup转换成BeautifulSoup对象,最后输出其中的<h1>标签中的文本,代码以下:
1 __author__ = 'f403' 2 #coding = utf-8 3 from urllib.request import urlopen 4 from bs4 import BeautifulSoup 5 html = urlopen("http://www.heibanke.com/lesson/crawler_ex00/") 6 bsobj = BeautifulSoup(html,"html.parser") 7 print(bsobj.h1)