E
E
Ernest Vardanyan2020-05-07 16:54:37
Python
Ernest Vardanyan, 2020-05-07 16:54:37

How to save parsing result in python through Selenium in Excel?

I wrote the code for the parser, it gives me the data that I need and I would like it to save everything in an Excel document, do I need to import csv? I am attaching the code, do not look at its beauty, I am a beginner (but if you correct something somewhere, I will be grateful)

from selenium import webdriver
import time
from selenium.common.exceptions import NoSuchElementException

browser=webdriver.Firefox()
browser.maximize_window()
Add=browser.get('https://one-xskbdc.world/ru/live/Mortal-Kombat/1252965-Mortal-Kombat-X/')

browser.find_element_by_xpath('//*[@id="games_content"]/div/div[1]/div/div/div[2]/div/div[1]/div[1]/a/span/div[2]').click()
time.sleep(5)

browser.find_element_by_xpath('//*[@id="hottest_games"]/div/div[1]/div/div/div[2]/div/ul/li[1]/a').click()
time.sleep(3)

bets=browser.find_element_by_class_name('u-fg').text
print(bets)
bets2=browser.find_element_by_id('allBetsTable').text
print(bets2)
bets3=browser.find_element_by_class_name('cyber-stat-table').text
print(bets3)

if bets3!=NoSuchElementException:
    print(bets3)
else:
    print('Нет данных')

try:
    print(bets3)==NoSuchElementException
except NoSuchElementException:
    print('Бой не начался')


browser.get('https://one-xskbdc.world/ru/live/Mortal-Kombat/1252965-Mortal-Kombat-X/')
browser.find_element_by_xpath('//*[@id="games_content"]/div/div[1]/div/div/div[3]/div/div[1]/div[1]/a/span/div[2]').click()
time.sleep(5)

browser.find_element_by_xpath('//*[@id="hottest_games"]/div/div[1]/div/div/div[2]/div/ul/li[1]/a').click()
time.sleep(3)

rest=browser.find_element_by_class_name('u-fg').text
print(rest)
rest2=browser.find_element_by_id('allBetsTable').text
print(rest2)
rest3=browser.find_element_by_class_name('cyber-stat-table').text
print(rest3)

if rest3!=NoSuchElementException:
    print(rest3)
else:
    print('Нет данных')

try:
    print(rest3)
except NoSuchElementException:
    print('Бой не начался')


browser.get('https://one-xskbdc.world/ru/live/Mortal-Kombat/1252965-Mortal-Kombat-X/')
browser.find_element_by_xpath('//*[@id="games_content"]/div/div[1]/div/div/div[4]/div/div[1]/div[1]/a/span/div[2]').click()
time.sleep(5)
browser.find_element_by_xpath('//*[@id="hottest_games"]/div/div[1]/div/div/div[2]/div/ul/li[1]/a').click()
time.sleep(3)

grow=browser.find_element_by_class_name('u-fg').text
print(grow)
grow2=browser.find_element_by_id('allBetsTable').text
print(grow2)
grow3=browser.find_element_by_class_name('cyber-stat-table').text
print(grow3)

if grow3!=NoSuchElementException:
    print(grow3)
else:
    print('Нет данных')

try:
    print(grow3)
except NoSuchElementException:
    print('Бой не начался')


browser.get('https://one-xskbdc.world/ru/live/Mortal-Kombat/1252965-Mortal-Kombat-X/')
browser.find_element_by_xpath('//*[@id="games_content"]/div/div[1]/div/div/div[5]/div/div[1]/div[1]/a/span/div[2]').click()
time.sleep(5)

browser.find_element_by_xpath('//*[@id="hottest_games"]/div/div[1]/div/div/div[2]/div/ul/li[1]/a').click()
time.sleep(3)

grab=browser.find_element_by_class_name('u-fg').text
print(grab)
grab2=browser.find_element_by_id('allBetsTable').text
print(grab2)
grab3=browser.find_element_by_class_name('cyber-stat-table').text
print(grab3)

if grab3!=NoSuchElementException:
    print(grab3)
else:
    print('Нет данных')

try:
    print(grab3)
except NoSuchElementException:
    print('Бой не начался')


browser.close()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Karbivnichy, 2020-05-07
@Ernest123

The easiest way is to save it to a csv file and then import it into excel.
CSV files
In general, you can write csv without any libraries.

A
Andrey_Dolg, 2020-05-07
@Andrey_Dolg

openpyxl

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question