Python网络爬虫(1)

来源:互联网 发布:node express -e 编辑:程序博客网 时间:2024/06/05 04:53

爬虫三步:请求 解析 存储


import requests   #导入requests 库

r=requests.get('http://www.wise.xmu.edu.cn/people/faculty')

html=r.content    #获取网页全部内容

print r.status_code,r.encoding   #返回请求状态 字码形式

from bs4 import BeautifulSoup#利用bs4进行解析

soup=BeautifulSoup(html,'html.parser')

div_people_list=soup.find('div',attrs={'class':'people_list'})

a_s=div_people_list.find_all('a',attrs={'target':'_blank'})

for a in a_s:

url=a['href']

name=a.get_text()

print name,url#直接打印出来,就当存储了

0 0
原创粉丝点击