python爬取足球直播吧五大聯(lián)賽積分榜
本文實(shí)例為大家分享了python爬取足球聯(lián)賽積分榜的具體代碼,供大家參考,具體內(nèi)容如下
使用BeautifulSoup4解析爬取足球直播吧五大聯(lián)賽積分榜信息;
#! /usr/bin/python3
# -*- coding:utf-8 -*-
from urllib.request import urlopen
from urllib.request import quote
from bs4 import BeautifulSoup
import time
import re
import json
import pymysql
url="https://data.zhibo8.cc/pc_main_data/#/dejia/index1"
response = urlopen(url)
bs = BeautifulSoup(response,"html.parser")
# print(bs)
liansai_s = bs.select("ul.data_nav > li")
# print(liansai_lists)
# <li ng-class="{current:current==0}" ng-click="selcuptype(0,'NBA')">
# <a data-index="nba" href="#/team_nba/nba" rel="external nofollow" name="NBA">
# <div class="data_item" ng-class="{current2:current==0}">NBA</div>
# <div class="data_item_logo"><img src="images/nba.png"/></div>
# </a>
# </li>
liansai_lists = []
for liansai in liansai_s:
# print(liansai)
ls = []
href = liansai.select("a")[0].get("href")
# print(href)
lsName = liansai.select("a > div.data_item")[0].text
ls.append(href)
ls.append(lsName)
liansai_lists.append(ls)
# print(liansai_lists)
#{
# '排名': '1',
# 'teamId': '565',
# '球隊(duì)': '巴塞羅那',
# '場次': '29',
# '勝': '23',
# '平': '6',
# '負(fù)': '0',
# '進(jìn)/失球': '74/13',
# '凈勝球': '61',
# '積分': '75',
# '球隊(duì)圖標(biāo)': 'http://duihui.qiumibao.com/zuqiu/basailuona.png',
# '字體顏色': '#e62e2e',
# '夜間字體顏色': '#af2d2d',
# '背景顏色': '#ffffff',
# '球隊(duì)名稱': '巴塞羅那'
# },
location = ''
def insert_into_db(lists):
#將數(shù)據(jù)寫入到數(shù)據(jù)庫中
con = pymysql.connect(host="localhost", user="root", password="root", database="zhi_bo_ba", charset='utf8', port=3306)
# 游標(biāo)。 作用 就等同于 JDBC 中的 Statement
cursor = con.cursor()
for record in lists:
print(record)
sql_insert = "insert into jifenbang (liansai, paiming, qiudui, changci, sheng,ping,fu,jinqiu_shiqu,jingsheng,jifen) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
cursor.execute(sql_insert, record)
con.commit()
cursor.close()
con.close()
def jifenbang(str):
# print(str)
datas = urlopen(str)
#加載json類型的數(shù)據(jù)
datas = json.load(datas)
jifen_list = []
for info in datas['data']:
j_f = []
j_f.append(location)
j_f.append(info['排名'])
j_f.append(info['球隊(duì)'])
j_f.append(info['場次'])
j_f.append(info['勝'])
j_f.append(info['平'])
j_f.append(info['負(fù)'])
j_f.append(info['進(jìn)/失球'])
j_f.append(info['凈勝球'])
j_f.append(info['積分'])
jifen_list.append(j_f)
print(jifen_list)
insert_into_db(jifen_list)
# https://dc.qiumibao.com/shuju/public/index.php?_url=/data/index&league=聯(lián)賽&tab=%積分榜&year=[year]
# https://dc.qiumibao.com/shuju/public/index.php?_url=/data/index&league=聯(lián)賽&tab=球員榜&type=射手榜&year=[year]
urls="https://dc.qiumibao.com/shuju/public/index.php?_url=/data/index&league="
list = ['西甲','英超','意甲','德甲','法甲','中超','中甲']
for aa in liansai_lists:
if aa[1] in list:
location = aa[1]
new_url = '%s%s&tab=%s&year=[year]' % (urls,quote(aa[1]),quote('積分榜'))
jifenbang(new_url)
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Python 爬取攜程所有機(jī)票的實(shí)例代碼
- 使用python爬取B站千萬級(jí)數(shù)據(jù)
- python爬取網(wǎng)頁內(nèi)容轉(zhuǎn)換為PDF文件
- python爬取網(wǎng)頁轉(zhuǎn)換為PDF文件
- Python實(shí)現(xiàn)的爬取網(wǎng)易動(dòng)態(tài)評(píng)論操作示例
- 通過抓取淘寶評(píng)論為例講解Python爬取ajax動(dòng)態(tài)生成的數(shù)據(jù)(經(jīng)典)
- Python實(shí)現(xiàn)爬取知乎神回復(fù)簡單爬蟲代碼分享
- python爬取網(wǎng)站數(shù)據(jù)保存使用的方法
- 以視頻爬取實(shí)例講解Python爬蟲神器Beautiful Soup用法
- python爬取個(gè)性簽名的方法
相關(guān)文章
Python復(fù)數(shù)屬性和方法運(yùn)算操作示例
這篇文章主要介紹了Python復(fù)數(shù)屬性和方法運(yùn)算操作,結(jié)合實(shí)例形式分析了Python復(fù)數(shù)運(yùn)算相關(guān)操作技巧,代碼注釋備有詳盡說明,需要的朋友可以參考下2017-07-07
Python根據(jù)給定模型進(jìn)行特征權(quán)值計(jì)算
在機(jī)器學(xué)習(xí)中,特征權(quán)重的計(jì)算是理解模型如何做出預(yù)測的重要步驟,本文將詳細(xì)介紹如何使用Python根據(jù)給定模型計(jì)算特征權(quán)重,希望對(duì)大家有一定的幫助2024-11-11
Windows 7下Python Web環(huán)境搭建圖文教程
這篇文章主要為大家詳細(xì)介紹了Windows 7下Python Web環(huán)境搭建圖文教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-03-03
Python如何實(shí)現(xiàn)Excel的最合適列寬(openpyxl)
這篇文章主要介紹了Python如何實(shí)現(xiàn)Excel的最合適列寬(openpyxl),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02
Win10下安裝CUDA11.0+CUDNN8.0+tensorflow-gpu2.4.1+pytorch1.7.0+p
這篇文章主要介紹了Win10下安裝CUDA11.0+CUDNN8.0+tensorflow-gpu2.4.1+pytorch1.7.0+paddlepaddle-gpu2.0.0,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03

