完整代码!

​
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()

​

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐