爬虫三步:请求 解析 存储
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 #直接打印出来,就当存储了
本文介绍了一个简单的Python爬虫案例,演示了如何使用requests和BeautifulSoup库从厦门大学智慧学院网站抓取教授名单及其链接。首先通过requests发送HTTP请求获取网页内容,接着利用BeautifulSoup解析HTML并提取目标数据。
9453

被折叠的 条评论
为什么被折叠?



