声明:
1、 学生刚开始学习爬虫,代码会有很多不严谨,也较为粗糙,单纯用于广大网友参考,希望能起到一定的帮助
2、 如果要转载,请标记出来源
3、本文纯粹用于技术练习,请勿用作非法途径
做题途中所遇问题:
无
代码块:
import requests
from bs4 import BeautifulSoup
#请求网址权限
response=requests.get("https://www.baidu.com/more/")
#自动索取编码
response.encoding=response.apparent_encoding
bs=BeautifulSoup(response.text,'html.parser')
#直接搜索所有的h3小标题来爬取所要的内容
base_title=bs.find_all('h3')
for title in base_title:
string=title.get_text()
print(string)
结果:
新上线最新
搜索服务
导航服务
社区服务
游戏娱乐
移动服务
站长与开发者服务
软件工具