I am new to webscraping/selenium/html & using a website to get all my past order details in a dataframe.
So far I am able to pull out all the details within the order but I want to run loop on each order so that rather than manually going into each order I automatically fetch details from each order.
But to get into each order I have not been able to extract information from click button (i.e "View Details" in this website) to construct url for each order.
For example this is the order below:
When I inspect on View Details
I get below highlight:
My attempt to get the details to create the url which is like: (xyz.com/account/orders/124994123/85405514)
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome('path/chromedriver.exe')
driver.get("https://www.URL.COM")
urls = driver.find_elements(By.CSS_SELECTOR, ".css-901oao.css-bfa6kz.r-tdq03u.r-1oke55r.r-1b43r93.r-majxgm")
orders_list = []
for tag in urls:
orders_list.append(tag.get_attribute('href'))
print(orders_list)
# output
[]
When I use tag.text
then I get below results:
urls = driver.find_elements(By.CSS_SELECTOR, ".css-901oao.css-bfa6kz.r-tdq03u.r-1oke55r.r-1b43r93.r-majxgm")
# .css-1dbjc4n.r-1awozwy.r-14lw9ot.r-cdmcib.r-18grtmt.r-5kkj8d.r-1777fci.r-ymttw5.r-1f1sjgu
orders_list = []
for tag in urls:
orders_list.append(tag.text)
print(orders_list)
['View Details', 'View Details', 'View Details', 'View Details', 'View Details', 'View Details', 'View Details', 'View Details', 'View Details', 'View Details', 'View Details', 'View Details', 'View Details', 'View Details', 'View Details', 'View Details', 'View Details', 'View Details', 'View Details', 'View Details']
But haven't been able to pull the information that can take me to the subsequent webpage of order details.
UPDATE: outer html
of View Details
button
<div dir="auto" class="css-901oao css-bfa6kz r-tdq03u r-1oke55r r-1b43r93 r-majxgm">View Details</div>
html of webpage after clicking on View Details
:
github link for html