Python Forum

Full Version: how can I find this by tag, instead of XPATH?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
here is what I'm looking for:
[Image: I0vHOiOm]

I want the events under the content list class;
I use this XPATH template, and loop through, and it works fine:
template = '//*[@id="main-content"]/div[2]/div/div[6]/div/div[2]/div[2]/div/div/div[{}]'

However this seems bulky and ugly looking, and I'm not sure if it'll break at some point.
Is there a way I can get the
div class = "content list"
div data-type = "events"
Image Link

Here's the image link< I couldn't edit it properly.
bump:


as I mentioned I am looking to scrape, using selenium,

<div class = "content list">
<div data-type = "events>


I am able to use a template, but I'm wondering if theres a way to do it with tag names or css names?
template = '//*[@id="main-content"]/div[2]/div/div[6]/div/div[2]/div[2]/div/div/div[{}]'



Image Link


here is my current code


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

driver = webdriver.Chrome("C:\Windows************************")
driver.get("https://www.fxva.com/events/?bounds=false&view=list&sort=date")
template = '//*[@id="main-content"]/div[2]/div/div[6]/div/div[2]/div[2]/div/div/div[{}]'





class Scraper:
def __init__(self):
self.h2 = []
self.h3 = []

def scrape(self):
for i in range(1, 10):
self.h2.append(template.format(i))
for i in self.h2:
self.h3.append(driver.find_element(By.XPATH, str(i)).text)
return self.h3
bump:


as I mentioned I am looking to scrape, using selenium,

<div class = "content list">
<div data-type = "events>


I am able to use a template, but I'm wondering if theres a way to do it with tag names or css names?
template = '//*[@id="main-content"]/div[2]/div/div[6]/div/div[2]/div[2]/div/div/div[{}]'



Image Link


here is my current code


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

driver = webdriver.Chrome("C:\Windows************************")
driver.get("https://www.fxva.com/events/?bounds=false&view=list&sort=date")
template = '//*[@id="main-content"]/div[2]/div/div[6]/div/div[2]/div[2]/div/div/div[{}]'





class Scraper:
def __init__(self):
self.h2 = []
self.h3 = []

def scrape(self):
for i in range(1, 10):
self.h2.append(template.format(i))
for i in self.h2:
self.h3.append(driver.find_element(By.XPATH, str(i)).text)
return self.h3