【源代码】python爬虫,爬取足球赛制比分

完整代码!

​
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
import time
from bs4 import BeautifulSoup
import select
import socket
import xlwt
import xlrd
from lxml import etree
import requests
import csv
import parsel
 
 
#新建表头表格
with open ('python.csv', mode='a',encoding='gbk',newline='') as f :
        csvwriter = csv.writer(f)
        csvwriter.writerow(["轮次","主队","比分","客队","主队指数","盘口","客队指数","半场比分"])
 
options = webdriver.EdgeOptions()
 
#关闭控制台错误显示
options.add_experimental_option('excludeSwitches', ['enable-logging'])
 
#不显示EDGE浏览器
options.add_argument('headless')
 
browser = webdriver.Edge(options=options)
browser.get("https://info.310win.com/cn/League/31.html")
time.sleep(2)
 
 
 
#点击切换欧指
browser.find_element('xpath','//*[@id="Table3"]/tbody/tr[1]/td[6]/span[1]/select').click()
browser.find_element('xpath','//*[@id="Table3"]/tbody/tr[1]/td[6]/span[1]/select/option[3]').click()
 
#循环获取轮次
like = browser.find_elements('class name','lsm2')
for x in like :
     
    x.click()
    time.sleep(2)
    li = browser.find_elements('xpath','//*[@id="Table3"]/tbody/tr[@align="center"]')
    #循环获取同行数据
    for lis in li :
        rounds = lis.find_element('xpath','.//td[1]').text
        hometeam = lis.find_element('xpath','.//td[3]').text
        score = lis.find_element('xpath','.//td[4]').text
        guestteam = lis.find_element('xpath','.//td[5]').text
        htscore = lis.find_element('xpath','.//td[6]').text
        Handicap = lis.find_element('xpath','.//td[7]').text
        gtscore = lis.find_element('xpath','.//td[8]').text
        firsthalf = lis.find_element('xpath','.//td[10]').text
 
        #print(lunci)
 
        #把获取的数据输出致csv表格
        with open ('python.csv', mode='a',encoding='gbk',newline='') as f :
            csvwriter = csv.writer(f)
            csvwriter.writerow([rounds,hometeam,"'"+score,guestteam,htscore,Handicap,gtscore,"'"+firsthalf])
    print(x.text)
    if x.text == '1' :
        break
 
 
browser.close()

​

  • 11
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码农之家★资源共享

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值