爬取【乐彩网】双色球历史获奖红蓝球数据
最终存到excel中
爬取数据要求为:
代码如下:
import requests
from lxml.html import etree
import re
cookies = {
'PHPSESSID': 'p9hhd41uma2qtffng5vu1c8pa4',
'pgv_pvi': '9924044800',
'pgv_si': 's9373211648',
}
headers = {
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Language': 'zh-CN,zh;q=0.9',
}
all_detail_links_list = []
def all_17500():
response = requests.get('http://www.17500.cn/ssq/all.php', headers=headers, cookies=cookies, verify=False)
res_html = etree.HTML(response.text)
old_LeCaiNet_links = res_html.xpath('//font[@id="SF"]/a/@href')
old_LeCaiNet_links_list = []
for old_LeCaiNet_link in old_LeCaiNet_links:
old_LeCaiNet_link = 'http://www.17500.cn/ssq/'+old_LeCaiNet_link
old_LeCaiNet_links_list.append(old_LeCaiNet_link)
oldyear_17500(old_LeCaiNet_links_list) #取出老旧年份的各期链接
new_LeCaiNet_links = res_html.xpath('//font[@id="SF"]/p/a/@href')
for new_LeCaiNet_link in new_LeCaiNet_links:
new_L