Home > Software design >  How to get multiple text from single column with selenium?
How to get multiple text from single column with selenium?

Time:07-21

I'm new for selenium. I've try and I don't know how to locate those specific position. How can I get all genre from top 200 games(4 pages) at once?

website link: https://playtoearn.net/blockchaingames/Ethereum/All-Genre/All-Status/All-Device/All-NFT/All-PlayToEarn/All-FreeToPlay

example

First of all, I want to get all top 50 game from 1st page.

My code is as follows:

from selenium import webdriver
from selenium.webdriver.common.by import By

PATH = "C:/Users/user/D/chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://playtoearn.net/blockchaingames/Ethereum/All-Genre/All-Status/All-Device/All-NFT/All-PlayToEarn/All-FreeToPlay")


for i in range(2, 51):
    genre = "/html/body/div[3]/div[6]/div/table[2]/tbody/tr["   str(i)   "]/td[4]"
    titles = driver.find_elements(By.XPATH, genre)
    for title in titles:
        print(title.text)

Output:

BREEDING
CARD
PVP
MINIGAME
OPEN-WORLD
VIRTUAL-WORLD
LOGIC
OPEN-WORLD
SIMULATION
MMO
MOBA
STRATEGY
CARD
DEFI
SPACE
ADVENTURE
VIRTUAL-WORLD
FANTASY
MMORPG
ACTION
FANTASY
RPG
ACTION
ADVENTURE
SHOOTER
MINIGAME
VIRTUAL-REALITY
VIRTUAL-WORLD
CARD
COLLECTIBLE
PVP
AUTO-BATTLER
DEFI
RPG
CARD
COLLECTIBLE
SCI-FI
CARD
PVP
STRATEGY
MMO
ARCADE
MINIGAME
VIRTUAL-WORLD
RACING
SPORTS
COLLECTIBLE
OPEN-WORLD
VIRTUAL-WORLD
ADVENTURE
COLLECTIBLE
MMORPG
BUILDING
SIMULATION
MOBA
PVP
ACTION
ADVENTURE
COLLECTIBLE
AUTO-BATTLER
BATTLE-ROYALE
DEFI
ACTION
SCI-FI
SHOOTER
ESPORTS
SCI-FI
SHOOTER
MINIGAME
VIRTUAL-REALITY
VIRTUAL-WORLD
ARCADE
CASUAL
MINING
BUILDING
MMO
STRATEGY
FITNESS
MOVE-TO-EARN
SPORTS
ACTION
FANTASY
RPG
ACTION
ADVENTURE
RPG
ADVENTURE
RPG
ACTION
PLATFORMER
SOCIAL
ACTION
ADVENTURE
MMORPG
MMO
PARTY
PVP
SCI-FI
TOWER-DEFENSE
ACTION
BATTLE-ROYALE
PVP
ADVENTURE
FANTASY
MMORPG
MMO
STRATEGY
TOWER-DEFENSE
CARD
FANTASY
SPORTS
CARD
COLLECTIBLE
FIGHTING
ADVENTURE
ESPORTS
RACING
ARCADE
AUTO-BATTLER
PVP
COLLECTIBLE
COLLECTIBLE
PVP
SPORTS
LOGIC
PUZZLE
BRAWLER
MOBA
FANTASY
SCI-FI
SHOOTER
CARD
PVP

I get the result that a bit different, compare to the website

CodePudding user response:

I had done some research on the internet and solve the problem by myself!

The code is as follows:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait          
from selenium.webdriver.support import expected_conditions as EC
import time

PATH = "C:/Users/user/D/chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://playtoearn.net/blockchaingames/Ethereum/All-Genre/All-Status/All-Device/All-NFT/All-PlayToEarn/All-FreeToPlay")
time.sleep(2)

for x in range(4):
    for i in range(2, 52):
        genre = "/html/body/div[3]/div[6]/div/table[2]/tbody/tr["   str(i)   "]/td[4]"
        titles = driver.find_elements(By.XPATH, genre)
        for title in titles:
            print(title.text)
    nextpage = driver.find_element(By.XPATH, "/html/body/div[3]/div[8]/nav/ul/li[10]/a") 
    driver.execute_script("arguments[0].click();", nextpage)

driver.quit()

CodePudding user response:

Use text-align : left; for your issue

  • Related