当前位置:网站首页>爬取彩票数据
爬取彩票数据
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
边栏推荐
猜你喜欢

小区房价可视化
Best practices for MySQL storage time

Export of data
![[leetcode 59] spiral matrix II](/img/6e/58e600272797563129d2b325a054b5.png)
[leetcode 59] spiral matrix II

Mysql database foundation

20 excellent plug-ins recommended by idea

SQL sorts according to the specified content

Integration and induction of knowledge points of automatic control principle (Han min version)

如何安装jsonpath包

Cf1427c the hard work of paparazzi
随机推荐
[leetcode 6] zigzag transformation
Kibana search syntax
基于Sentinel+Nacos 对Feign Client 动态添加默认熔断规则
How SYSTEMd uses / etc / init D script
3. Continuous integer
Export of data
程序設計訓練
Common sense of thread pool
Object转Json差异之Gson fastJson jackson 修改字段名
Rust: Tcp 服务器与客户端的一个简单例子
St table template
Programming training
[leetcode 54] spiral matrix
Basemap库绘制地图
程序设计训练
如何安装jsonpath包
Problems and solutions of database migration
Robocode教程4——Robocode的游戏物理
Solution to the trial of ycu Blue Bridge Cup programming competition in 2021
Rainbow (DP)