How can i extract href from this html using selenium?

GigaByte

I want to extract href from the following html using selenium:

   <div class="resultsContainer clearfix" data-index="0"> 
        <div class="tableItem eventType">
            <span class="tileNumber">1.&nbsp;</span>         
            <span class="miles">0 mi</span>      
        </div>   
        <div class="tableItem eventTime">
            <span class="tileNumber">1.&nbsp;</span> 
                <ul>         
                    <li class="placeName clearfix">
                        <a class="placeName" href="/en/home/play/facility-listing/facility-details.html?facilityId=777EMBARCADEROROAD-CA-94301">Rinconada Park</a></li>    
                    <li class="timeNumber phoneNumber">(650) 463-4900</li>        
                </ul>       
        </div>       
        <div class="tableItem eventSize">     
            <ul>       
                <li>
                    <span class="eventNameType"># of Courts:</span>                     
                    <span class="eventNameValue">9</span>
                </li>          
                <li>
                    <span class="eventNameType">Court Size:</span> 
                    <span class="eventNameValue"> 36', 60', 78'</span>
                </li>
                <li>
                    <span class="eventNameType">Indoor Courts:</span>
                    <span class="eventNameValue">No</span>
                 </li>         
            </ul>       
        </div>       

        <div class="tableItem eventLocation">         
            <ul>           
                <li class="mileValue">0 mi</li>           
                <li>777 Embarcadero Road</li>           
                <li>Palo Alto, California, 94301</li>         
            </ul>       
        </div>       

        <div class="tableItem eventMoreInfo">         
            <div class="seeMoreBtn">           
                <a class="btn primaryBtn" href="/en/home/play/facility-listing/facility-details.html?facilityId=777EMBARCADEROROAD-CA-94301">MORE INFO</a>         
            </div>       
        </div>     
    </div>

The selenium(Python) code that i'm using is as follows:

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains


# ----------------------------------------------HANDLING-SELENIUM-STUFF-------------------------------------------------

driver = webdriver.Chrome()
time.sleep(5)
driver.get('https://www.usta.com/en/home/play/facility-listing.html?searchTerm=&distance=5000000000&address=Palo%20Alto,%20%20CA')
wait = WebDriverWait(driver,5)
time.sleep(5)
links = driver.find_element_by_xpath("//div[@class='seeMoreBtn']/a")
print(links.text)
time.sleep(3)
for link in links:
    print(link.get_attribute("href"))
driver.close()

Following is the webpage from where i want to extract the links using the xpath above(more precisely links under MoreInfo button section)

On executing the above code i'm getting this error:

Traceback (most recent call last):
  File "E:/Python/CSV/scraperscrapero.py", line 23, in <module>
    for link in links:
TypeError: 'WebElement' object is not iterable

But the above XPATH on this page contains 5 Buttons of MoreInfo.

I just wanted to get those five links which are under a tag of Button MoreInfo

Subburaj

You have used find_element instead of find_elements.

Please change the below line and then check

links = driver.find_elements_by_xpath("//div[@class='seeMoreBtn']/a")

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I get href links from HTML using Python?

How can I get a href,Image src,title from given html using DomDocument

How can i extract the links from the site that contains pagination?(using selenium)

How can I extract links from HTML?

Python - how to extract href using BeautifulSoup without selenium (onclick)

how can i extract this value from a website, with python, selenium and chromedriver

How can I extract a specific text in an html code with Selenium and Python

How to extract the href attribute of the first search result using Selenium and Python

How to extract the text from the HTML using Selenium and Python

How can I extract all links (href) in an HTML file?

On a mobile device, can I extract data from html using a WebView?

How can I click on the link here with using id.class.href python selenium, I using pyCharm

Selenium how to extract href from attributes

How can I Extract information from HTML page using Python?

How can i extract the words which are starting with "icon" from HTML code using python

How can I extract information from a HTML code using Python + Selenium?

How can I prevent href from firing using React onClick?

How can I extract specific texts from an HTML file by using Notepad++ or Adobe Dreamweaver?

How do I extract a table from a webpage using selenium when the table is not constructed with the HTML 'table' tag?

How can I scrape text from tooltip using selenium? Page does not contain tooltip html

How do i extract data from yelp using selenium python

How can I extract href links from a within a table th using BeautifulSoup

How to extract link from href using beautifulsoup

How do I get href attribute value from the given HTML using Python+Selenium?

How can i extract Href and title from this HTML

How to extract multiline content from the <pre> tag in html using Selenium

How can I extract HREF content with selenium?

How can I extract the headers from multiple HTML tables using C# HTMLAgilityPack?

How can I extract the text from a webelement using selenium