日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

Crawler:基于BeautifulSoup库+requests库+伪装浏览器的方式实现爬取14年所有的福彩网页的福彩3D相关信息,并将其保存到Excel表格中

發(fā)布時間:2025/3/21 HTML 46 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Crawler:基于BeautifulSoup库+requests库+伪装浏览器的方式实现爬取14年所有的福彩网页的福彩3D相关信息,并将其保存到Excel表格中 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Crawler:Python爬取14年所有的福彩信息,利用requests庫和BeautifulSoup模塊來抓取中彩網(wǎng)頁福彩3D相關的信息,并將其保存到Excel表格中

?

?

目錄

輸出結(jié)果

核心代碼


?

?

?

輸出結(jié)果

中國彩票網(wǎng)

本來想做個科學預測,無奈,我看不懂爬到的數(shù)據(jù)……

得到數(shù)據(jù):3D(爬取的14年所有的福彩信息).rar

好吧,等我看到了再用機器學習算法預測一下……
完整代碼,請點擊獲取
?

?

核心代碼

import requests import BeautifulSoup import xlwt import time#獲取第一頁的內(nèi)容 def get_one_page(url):headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36'}response = requests.get(url,headers=headers)if response.status_code == 200:return response.textreturn None#解析第一頁內(nèi)容,數(shù)據(jù)結(jié)構(gòu)化 def parse_one_page(html):soup = BeautifulSoup(html,'lxml')i = 0for item in soup.select('tr')[2:-1]:yield{'time':item.select('td')[i].text,'issue':item.select('td')[i+1].text,'digits':item.select('td em')[0].text,'ten_digits':item.select('td em')[1].text,'hundred_digits':item.select('td em')[2].text,'single_selection':item.select('td')[i+3].text,'group_selection_3':item.select('td')[i+4].text,'group_selection_6':item.select('td')[i+5].text,'sales':item.select('td')[i+6].text,'return_rates':item.select('td')[i+7].text}#將數(shù)據(jù)寫入Excel表格中 def write_to_excel():f = xlwt.Workbook() sheet1 = f.add_sheet('3D',cell_overwrite_ok=True)row0 = ["開獎日期","期號","個位數(shù)","十位數(shù)","百位數(shù)","單數(shù)","組選3","組選6","銷售額","返獎比例"]#寫入第一行for j in range(0,len(row0)):sheet1.write(0,j,row0[j])#依次爬取每一頁內(nèi)容的每一期信息,并將其依次寫入Exceli=0for k in range(1,247):url = 'http://kaijiang.zhcw.com/zhcw/html/3d/list_%s.html' %(str(k)) ……f.save('3D.xls')def main():write_to_excel()if __name__ == '__main__':main()

?

總結(jié)

以上是生活随笔為你收集整理的Crawler:基于BeautifulSoup库+requests库+伪装浏览器的方式实现爬取14年所有的福彩网页的福彩3D相关信息,并将其保存到Excel表格中的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。