当前位置:网站首页>Crawl lottery data
Crawl lottery data
2022-04-23 18:00:00 【Round programmer】
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':' Yours 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")# date
red=i.get("red","notfound")# Red sign
blue=i.get('blue',"notfound")# Blue
print(red,blue)
with open('/media/liu/_dde_data/project/spider/ lottery /' + " Bicolor " + '.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") # date
red = i.get("red", "notfound") # Red sign
print(time,red)
with open('/media/liu/_dde_data/project/spider/ lottery /' + "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")# date
red=i.get("red","notfound")# Red sign
blue=i.get('blue',"notfound")# Blue
print(red,blue)
with open('/media/liu/_dde_data/project/spider/ lottery /' + " Seven music colors " + '.csv', 'a+') as f:
f_csv = csv.writer(f)
f_csv.writerow([time, red, blue])
ssq_craw()
sd_craw()
qlc_craw()
版权声明
本文为[Round programmer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230545315791.html
边栏推荐
猜你喜欢
Random number generation of C #
Remember using Ali Font Icon Library for the first time
Map basemap Library
Go language JSON package usage
Theory and practice of laser slam in dark blue College - Chapter 2 (odometer calibration)
YOLOv4剪枝【附代码】
Classification of cifar100 data set based on convolutional neural network
极致体验,揭晓抖音背后的音视频技术
高德地图搜索、拖拽 查询地址
String function in MySQL
随机推荐
Thirteen documents in software engineering
[appium] write scripts by designing Keyword Driven files
Install pyshp Library
Uniapp custom search box adaptation applet alignment capsule
Using files to save data (C language)
Data stream encryption and decryption of C
Element calculation distance and event object
journal
Visualization of residential house prices
Implementation of k8s redis one master multi slave dynamic capacity expansion
Go language JSON package usage
Go对文件操作
Scikit learn sklearn 0.18 official document Chinese version
列錶的使用-增删改查
2022江西储能技术展会,中国电池展,动力电池展,燃料电池展
How to read literature
GDAL + ogr learning
JS get link? The following parameter name or value, according to the URL? Judge the parameters after
Flask项目的部署详解
Summary of floating point double precision, single precision and half precision knowledge