Home > Mobile >  How can i get the title of top selling games on steam using selenium in python
How can i get the title of top selling games on steam using selenium in python

Time:12-21

So I am trying to make a dataset which requires me get titles of steam top selling games in python

code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import pandas as pd
from selenium.webdriver.firefox.options import Options

options = Options()
options.binary_location = r"{binary_location}"
driver = webdriver.Firefox(executable_path=r"{driver_location}", options=options)

driver.get("https://store.steampowered.com/search/?filter=topsellers")

titles = driver.find_element_by_xpath("//span[@class='title']").text
titles

This only outputs the first title which is

Counter-Strike: Global Offensive

I need all the titles of the games which are present on the web page

Output

please don't suggest using beautifulsoup i specifically need using selenium in python

CodePudding user response:

You can search for multiple elements:

titles = driver.find_elements_by_xpath("//span[@class='title']").text

CodePudding user response:

You have to use find_elements instead of find_element:

titles = driver.find_elements(By.XPATH, "//span[@class='title']")

Then, using for loop you can get the text of each webelement:

for title in titles:
    print(title.text)
  • Related