R
R
Robot2052020-07-21 20:38:53
Python
Robot205, 2020-07-21 20:38:53

How to save numbers from website to excel?

Hello. There was such a task. There are several matches going on and you need to save W1 odds every 10 seconds in Excel until the matches are over. In the first column there will be the name, in the following coefficients. Please tell me how to implement

from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.get("https://zenitbet.com/live/view2/#!/sport134")
time.sleep(5)
a=[]
koef = driver.find_elements_by_xpath("//td[@class='cf'][1]")
for i in koef:
    h=i.find_element_by_xpath("..//b[@class='g-d g-d-s']")
    my_file = open('zenit.xls', 'a')
    my_file.write(h.text + i.text)

I want it to be like this
5f17278e3c4a8286180161.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-07-21
@Robot205

To write to an excel file, you need to use third-party modules, like XlsxWriter

import xlsxwriter

workbook = xlsxwriter.Workbook('hello.xlsx')
worksheet = workbook.add_worksheet()

worksheet.write('A1', 'Hello world')

workbook.close()

https://xlsxwriter.readthedocs.io/getting_started.html
Another option is to use csv files https://docs.python.org/3/library/csv.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question