2

In the website i visit there are 7 links of the following structure:

<tr>
 <td>
  <a href="some link i will need to visit" title="some title"> some text... Episode ....
  </a>
 </td>
 <td> some date </td>
</tr>

Now i use the following code to fetch the episodes and put them in a list

chromedriver = "C:/.../chromedriver.exe"

driver = webdriver.Chrome(chromedriver)

driver.get("link containing the content")

episodes = driver.find_elements_by_partial_link_text('Episode')

print "episodes found: ", len(episodes)

This always prints episodes found: 0. I've tried using a piece from the beginning of the hyperlink text, but it still doesn't work. Any help would be appreciated.

The link is this

VlassisFo
  • 650
  • 1
  • 8
  • 26

2 Answers2

2

Aside from what @nullpointer null-pointed out, notice the delay in the webpage load - the elements you are looking for are not immediately available and you need to wait for them to be present:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://kissanime.to/Anime/Hunter-x-Hunter-2011-Dub")

WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, "//a[contains(@title,'Episode')]")))

episodes = driver.find_elements_by_xpath("//a[contains(@title,'Episode')]")
print(len(episodes))

driver.close()

Prints 8.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
1

Looking upon the link provided the DOM is

<a href="/Anime/Hunter-x-Hunter-2011-Dub/Episode-007?id=126436" title="Watch anime Hunter x Hunter (2011) (Dub) Episode 007 online in high quality"> Hunter x Hunter (2011) (Dub) Episode 007</a>

In which case you can use the following as well :

episodes = driver.find_elements_by_xpath("//a[contains(@title,'Episode')]")

Edit: In case you want to refer to correct usage of chromedriver. Do have a look at :

Running webdriver chrome with Selenium

Community
  • 1
  • 1
Naman
  • 27,789
  • 26
  • 218
  • 353
  • This doesn't seem to work either :/ Could it be the chromedriver's fault? Also could you tell me where i can study the syntax you used inside the paarentheses? – VlassisFo Jun 05 '16 at 19:51
  • @Alan - https://www.w3.org/TR/xpath/#path-abbrev for the details on x path. In case of driver issue, you certainly should have got an exception. – Naman Jun 05 '16 at 19:54