背景:实习工作内容,对接业务人员因采购原材料,想要获取铝琔的历史价格
目标字段:品名,日期,价格
目的:爬取ADC12-F的历史价格。
1.调用相关库
import pymysql
import requests
from bs4 import BeautifulSoup
2.设置请求头
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36'
}
page = requests.get('http://m.baotaigroup.com.cn/index/offer/hoffer/id/9.html', headers = headers)
page.encoding = 'utf8'#保证不乱码
soup = BeautifulSoup(page.text, "html.parser")
3.解析网页,获取总页数
for num_page in soup.find_all("ul", class_="pagination"):#看下面图片框起来的内容
a=num_page.get_text()