1

I need to find all href inside class="mozaique"

My code:

gfd = driver.find_elements_by_xpath('/html[1]/body[1]/div[1]/div[4]/div[2]/div[1]/div[2]/div[1]/div[1]/div[2]/div[1]')

html: enter image description here

shad0w_wa1k3r
  • 12,955
  • 8
  • 67
  • 90
  • Hope it will help https://stackoverflow.com/questions/47653309/beautifulsoup-select-all-href-in-some-element-with-specific-class – EMKAY Sep 24 '18 at 14:51
  • Possible duplicate of [BeautifulSoup select all href in some element with specific class](https://stackoverflow.com/questions/47653309/beautifulsoup-select-all-href-in-some-element-with-specific-class) – shad0w_wa1k3r Sep 24 '18 at 14:53
  • you need to use getAttribute("href") to get link – Ankur Singh Sep 24 '18 at 16:58

2 Answers2

0

Below xpath should help you fetch all the links under tag:

<div> class='mozaique'</div>

Xpath:

//div[@class='mozaique']//a[contains(@href,'')]

You can print the href's using the below code snippet:

links = driver.find_elements_by_xpath('//div[@class='mozaique']//a[contains(@href,'')]')

for link in links:
    print(link.get_attribute("href"))
Kireeti Annamaraj
  • 1,037
  • 1
  • 8
  • 12
0

First, get your parent element:

parent = driver.find_element_by_class_name("mozaique")

Then get a list of all 'a' tags within your parent element.

a = parent.find_elements_by_tag_name("a")

Then run a loop to print the hrefs

for x in a:
    print(x.get_attribute("href"))
Mono
  • 146
  • 4