Python Forum
how can I find this by tag, instead of XPATH?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how can I find this by tag, instead of XPATH?
#1
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"
Reply
#2
Image Link

Here's the image link< I couldn't edit it properly.
Reply
#3
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
Reply
#4
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Find element using xpath engli 3 3,974 May-20-2020, 08:56 AM
Last Post: Larz60+
  need help with xpath pythonprogrammer 1 2,774 Jan-18-2020, 11:28 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020