selenium how to get the content of href within some targeted class

后端 未结 3 1539
北荒
北荒 2020-12-05 13:39

I am trying to retrieve the data from the webpage has the html in below

       
                      
相关标签:
3条回答
  • 2020-12-05 14:18

    As far as I am aware you can get the href by searching through the child elements

    div = self.driver.find_element_by_class_name('someclass')
    div.find_element_by_css_selector('a').get_attribute('href')
    
    0 讨论(0)
  • 2020-12-05 14:28

    This should do it for you:

    self.driver.find_element_by_css_selector('.someclass a').get_attribute('href')
    
    0 讨论(0)
  • if you search for special tag use from find_element_by_id or classname or xpath and then use get_attribute('href')

    in this example print all attribute for a tags

       ids = self.driver.find_elements_by_xpath('//*[@href]')
       for id in ids:
            print(id.get_attribute('href'))
           
    
    0 讨论(0)
提交回复
热议问题