-1

I've been trying to write a simple script in order to upload 200+ links to a website I'm working in (I have poor knowledge on python and even poorer in HTML, of course I wasn't working as a web developer, I just need to upload these links).

Well, the situation I'm in is the following: I am using Splinter(therefore, Python) in order to navigate in the website. Certain section titles of this website will be compared with values I have in a .csv table.

For instance, in this screenshot, I am looking for this link /admin/pages/5, and I would like to compare the link's title (Explorar subpáginas de 'MA111 - Cálculo I') with my .CSV table. The problem is the link's title doesn't appear in the website.

To find the link I would guess that I should use find_by_xpath(), but I don't know how to do it. I would guess it's something like this link.

I would appreciate any help! I hope I have made myself clear.

Community
  • 1
  • 1
orlandini
  • 123
  • 1
  • 6
  • What do you know initially about target element: link reference `href` or `title` or `a` element index/position in `DOM` and what output do you want to get? It's quite hard to understand your issue... – Andersson Mar 27 '17 at 17:35

1 Answers1

0

You first need to define how are you detecting that url, so for example, "it is always to the right of certain button", or "it is the second row in a table", that way you can build the respective xpath (which is a path to follow inside the DOM.

I am not entirely sure, but this could give you the solution

url = browser.find_by_xpath('//td[@class="children"]/a')[0]['href']

if you are finding a tag by the link name for example, try this:

url = browser.find_by_xpath('//a[contains(@title, "MA111 - Cálculo I")]')[0]['href']

If you check there, the xpath says "find in the entire DOM // a tag named a which contains "MA111 - Cálculo I" in the title attribute.

eLRuLL
  • 18,488
  • 9
  • 73
  • 99
  • First of all, thank you! Yes, it does give me one link, but the first one (because of the *[0]*). What I was wondering was: Is there someway for me to search the link whose title contains one word I am looking for? In the screenshot I've posted, for instance, I would like to search for "Cálculo I", for instance. – orlandini Mar 27 '17 at 17:56
  • thank you! I had to modify it slightly because I didn't specify exactly what I wanted. `browser.find_by_xpath('//a[contains(@title, "MA111 - Cálculo I") and contains(@title, "Explorar")]')[0]['href']` was the final version. Thank you very much p.s. Where could I find more information about xpath syntax? I think it might be useful in the future.. – orlandini Mar 27 '17 at 19:51
  • the [xpath tutorial](https://www.w3schools.com/xml/xpath_syntax.asp) would be the best source I think – eLRuLL Mar 27 '17 at 20:11