简体   繁体   English

如何从 selenium python 中提取 href 标签元素?

[英]how to extract a href tag elemnt from selenium python?

I am new to Selenium really and would appreciate help in the below case.我真的是 Selenium 的新手,在以下情况下将不胜感激。 I am trying to make a birthday bot for Facebook.我正在尝试为 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.我在禁用 js 的情况下运行 selenium,这使得代码更容易,因为我很难通过 Facebook 的最新 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如果我可以将_keys 发送到文本框或从中提取配置文件链接,两者都会有所帮助

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"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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