爬虫

1.urllib

获取服务器的一些信息。可以使用urllib

from urllib.request import urlopen

url="http://www.baidu.com"

html=urlopen(url)

print(html.info())   #打印信息

print(html.headers) #打印返回头信息

print(html.getcode())

 

2.bs4 查询维基百科某个页面的所有url链接

from bs4 import BeautifulSoup as bs

from urllib.request import urlopen

html=urlopen('http://en.wikipedia.org/wiki/Kevin_Bacom‘)

bsobj=bs(html,"html.parser")

for i in bsobj.findAll("a"):

    if "href" in i.attribs:

        print(i.attrs['href'])

posted on 2018-02-26 22:40  mingxiazhichan  阅读(98)  评论(0编辑  收藏  举报

导航