一、爬前准备
1、安装pip安装套件
pip install requests
pip install BeautifulSoup4
2、Chrome用户内建开发人员工具
检查—>Network—>Doc
3、编辑视窗
pip install jupyter
# 进行编辑:jupyter notebook
二、使用requests.get取得页面内容:
import requests
res = requests.get("http://finance.ifeng.com/" ) # 调用网页链接
res.encoding = "utf-8" # 汉显
print(res.text)
三、使用BeautifulSoup将页面内容剖析出来('html.parser'—剖析器)
1、范例提取页面相关内容:



2、取得特定css属性元素:


3、在网页的连接上,取得所有a标签内的链接

例:

3、确定元素抓取位置:

三、根据不同HTML标签取得对应内容

网友评论