当前位置:网站首页>爬取彩票数据
爬取彩票数据
2022-04-23 05:46:00 【圆滚滚的程序员】
import requests
import json
import csv
from user_agents import UA
def post_request(url,data):
HEADER = {
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9',
'Connection': 'keep-alive',
'User-Agent': UA,
'Cookie':'你的cookie',
'Host': 'www.cwl.gov.cn',
'Referer': 'http://www.cwl.gov.cn/kjxx/ssq/kjgg/',
'X-Requested-With': 'XMLHttpRequest',
}
try:
response = requests.post(
url=url,
headers=HEADER,
verify=True,
data=data,
timeout=20
)
res = bytes(response.text, response.encoding).decode("utf-8", 'ignore')
return res
except Exception as e:
pass
def ssq_craw():
url_ssq="http://www.cwl.gov.cn/cwl_admin/kjxx/findDrawNotice"
data = {
'name': 'ssq',
'issueCount': '100',
}
respon=json.loads(post_request(url=url_ssq,data=data))
data_list=respon["result"]
for i in data_list:
time=i.get("date","notfound")#日期
red=i.get("red","notfound")#红号
blue=i.get('blue',"notfound")#蓝号
print(red,blue)
with open('/media/liu/_dde_data/project/spider/彩票/' + "双色球" + '.csv', 'a+') as f:
f_csv = csv.writer(f)
f_csv.writerow([time, red, blue])
def sd_craw():
url_sd = "http://www.cwl.gov.cn/cwl_admin/kjxx/findDrawNotice"
data = {
'name': '3d',
'issueCount': '100',
}
respon = json.loads(post_request(url=url_sd,data=data))
data_list = respon["result"]
for i in data_list:
time = i.get("date", "notfound") # 日期
red = i.get("red", "notfound") # 红号
print(time,red)
with open('/media/liu/_dde_data/project/spider/彩票/' + "3D" + '.csv', 'a+') as f:
f_csv = csv.writer(f)
f_csv.writerow([time, red])
def qlc_craw():
url_ssq="http://www.cwl.gov.cn/cwl_admin/kjxx/findDrawNotice"
data = {
'name': 'qlc',
'issueCount': '100',
}
respon=json.loads(post_request(url=url_ssq,data=data))
data_list=respon["result"]
for i in data_list:
time=i.get("date","notfound")#日期
red=i.get("red","notfound")#红号
blue=i.get('blue',"notfound")#蓝号
print(red,blue)
with open('/media/liu/_dde_data/project/spider/彩票/' + "七乐彩" + '.csv', 'a+') as f:
f_csv = csv.writer(f)
f_csv.writerow([time, red, blue])
ssq_craw()
sd_craw()
qlc_craw()
版权声明
本文为[圆滚滚的程序员]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_39483957/article/details/108181076
边栏推荐
猜你喜欢
How SYSTEMd uses / etc / init D script
从源代码到可执行文件的过程
解决ArcGIS分区统计显示太多唯一值执行失败
Integration and induction of knowledge points of automatic control principle (Han min version)
Addition, deletion, query and modification of data
自动控制原理知识点整合归纳(韩敏版)
MySQL table constraints and table design
Motor and drive (Qi Jinqing Edition)
检测技术与原理
Export of data
随机推荐
Customized communication between threads (reentrantlock)
[leetcode 290] word rules
Calculation (enter the calculation formula to get the result)
定位器
1007 go running (hdu6808) in the fourth game of 2020 Hangzhou Electric Multi school competition
Cf6d lizards and fundamentals 2 problem solving
1. Calculate a + B
用C语言实现重写strcmp等四个函数
渔网道路密度计算
Event listener
Export the articles written in CSDN to PDF format
selenium+webdriver+chrome实现百度以图搜图
爬取蝉妈妈数据平台商品数据
Addition, deletion, modification and query of MySQL table
Best practices for MySQL storage time
C array
Understanding and installing MySQL
程序設計訓練
7-21日错题涉及知识点。
Guaba and Computational Geometry