简体   繁体   中英

how to extract a href tag elemnt from selenium python?

I am new to Selenium really and would appreciate help in the below case. I am trying to make a birthday bot for Facebook. I am running selenium with js disabled which makes the code easier since it is a little tough for me to maneuver through Facebook's latest UI. Now, I tried to access the textbox of the current birthdays but that I couldn't so I am trying to extract the profile link of all the friends who have a birthday today. I have tried using the below snippets, but nothing actually worked. Both would be helpful if either I can send_keys to the textbox or extract the profile link from

Please check the image for details.

birthday = driver.find_element_by_css_selector('bj cf cq')
containers=birthday.find_element_by_css_selector("[class='bj cf cq']")
containers=birthday.find_element_by_xpath('//*[@id="events_dashboard_calendar_container"]/div/article[1]/div')
birthdayslist= birthdaystoday.find_elements_by_css_selector("[class='ce cf cg']")

list=driver.find_element_by_xpath('//*[@id="events_dashboard_calendar_container"]/div/article[1]/div/ul/div[2]')

//*[@id="events_dashboard_calendar_container"]/div/article[1]/div/ul/div[2]
driver.find_elements_by_class_name("ce cf cg")

find_element_by_tag_name("a").get_property("href")

page source code

Use code below (indentation fixed):

birthdays = driver.find_elements_by_xpath("//div[@id='events_dashboard_calendar_container']//a")
for birthday in birthdays:
    print(birthday.get_attribute("href"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM