以下是使用Python爬取网页数据的代码:

import requests
from bs4 import BeautifulSoup

# 设置请求头
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}

# 构造请求参数
params = {
    'year': '',
    'province': '',
    'crop': '玉米',
    'variety': ''
}

# 发送请求
response = requests.get('http://202.127.42.47:6006/home/bigdataindex', headers=headers, params=params)

# 解析网页
soup = BeautifulSoup(response.content, 'html.parser')

# 获取表格数据
table = soup.find('table', class_='table')
rows = table.find_all('tr')
header = [cell.text.strip() for cell in rows[0].find_all('th')]
data = []
for row in rows[1:]:
    cells = row.find_all('td')
    data.append([cell.text.strip() for cell in cells])

# 打印结果
print(header)
for row in data:
    print(row)

该代码会输出所有年份,作物种类为玉米的数据。你可以根据需要调整请求参数,获取不同条件下的数据

使用Python从网址http20212742476006homebigdataindex爬取数据网页有年份、省份、作物种类、品种名称等选择输入项爬取所有年份作物种类为玉米的数据

原文地址: https://www.cveoy.top/t/topic/c8Qk 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录