import requests
import csv
from concurrent.futures import ThreadPoolExecutor
分析得到该页面的数据是从getPriceData.html
页面获取,并保存在csv文件中
创新互联长期为成百上千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为皇姑企业提供专业的成都网站制作、成都网站设计,皇姑网站改版等技术服务。拥有十载丰富建站经验和众多成功案例,为您定制开发。
得到url地址后,提取第一个页面内容
def download(url, num):
resp = requests.post(url).json()
for i in resp['list']:
temp = [i['prodName'], i['lowPrice'], i['highPrice'], i['avgPrice'], i['place'], i['unitInfo'], i['pubDate']]
csvwrite.writerow(temp)
if __name__ == "__main__":
url = 'http://www.xinfadi.com.cn/getPriceData.html'
download(url)
print('success')
** 此为第一个页面信息提取:**
分析页面数据显示规律,请求地址时页面携带页码和需要显示数据的条数,一共页,每页20条数据
设置100个线程提取页数据,同时每次请求时传入页码
def download(url, num):
data = {
"limit": 20,
"current": num
}
resp = requests.post(url, data=data).json()
for i in resp['list']:
temp = [i['prodName'], i['lowPrice'], i['highPrice'], i['avgPrice'], i['place'], i['unitInfo'], i['pubDate']]
csvwrite.writerow(temp)
print(f'{num}页提取完成')
if __name__ == "__main__":
url = 'http://www.xinfadi.com.cn/getPriceData.html'
# 设置100个线程
with ThreadPoolExecutor(100) as t:
for i in range(1, ):
t.submit(download(url, i))
print('success')
# 1、提取单页面
import requests
import csv
from concurrent.futures import ThreadPoolExecutor
f = open("data.csv", mode="w", encoding="utf-8")
csvwrite = csv.writer(f)
def download(url, num):
data = {
"limit": 20,
"current": num
}
resp = requests.post(url, data=data).json()
for i in resp['list']:
temp = [i['prodName'], i['lowPrice'], i['highPrice'], i['avgPrice'], i['place'], i['unitInfo'], i['pubDate']]
csvwrite.writerow(temp)
print(f'{num}页提取完成')
if __name__ == "__main__":
url = 'http://www.xinfadi.com.cn/getPriceData.html'
# 设置100个线程
with ThreadPoolExecutor(100) as t:
for i in range(1, ):
t.submit(download(url, i))
print('success')
以下为第1页~第199页数据: