# xpath confusion

**URL:** <https://forums.plex.tv/t/xpath-confusion/4429>\
**Category:** Dev/API Corner\
**Tags:** plugin-dev\
**Created:** [August 20, 2010, 7:34am UTC](https://forums.plex.tv/t/xpath-confusion/4429 "2010-08-20T07:34:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jcoff](https://avatars.discourse-cdn.com/v4/letter/j/3e96dc/32.png) [@jcoff](https://forums.plex.tv/u/jcoff)\
**Post date:** [August 20, 2010, 7:34am UTC](https://forums.plex.tv/t/xpath-confusion/4429/1 "2010-08-20T07:34:55Z")

</div>

I hope someone can help me… I’m confused about why this isn’t working. I am trying to use xpath and then loop thru elements to scrape info.   
  
  
  
This works, but then I’m at a lower level node than I want:

```auto

<br />
    content = XML.ElementFromURL(pageUrl, True)<br />
    for item in content.xpath('//div[@class="column span-16 item"]/h1'):<br />
			title = item.text<br />
<br />

```

  
  
This doesn't work but I think it should:  

```auto

<br />
    content = XML.ElementFromURL(pageUrl, True)<br />
    for item in content.xpath('//div[@class="column span-16 item"]'):<br />
			title = item.xpath('./h1').text<br />
<br />

```

  
  
It blows up on the ".text" for some reason. Here is the page I'm trying to parse:  
[http://tekpub.com/productions?tag=free](http://tekpub.com/productions?tag=free)  
  
For that example, the the broken code should actually be finding a title of "Concepts" for the first match. There's more I need to scape but I get the same problem for the rest as well. Any ideas what that wouldn't work?  
  
You can see the [whole thing here](http://github.com/jcoffman/PlexTekPub) if you want/need.  
  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![jam](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/jam/32/186050_2.png) [@jam](https://forums.plex.tv/u/jam)\
**Post date:** [August 20, 2010, 10:58am UTC](https://forums.plex.tv/t/xpath-confusion/4429/2 "2010-08-20T10:58:07Z")

</div>

xpath() will always return a list, even if there’s only one item - item.xpath(’.h1’)[0].text would probably work.

---

<div class="post-metadata">

**Author:** ![jcoff](https://avatars.discourse-cdn.com/v4/letter/j/3e96dc/32.png) [@jcoff](https://forums.plex.tv/u/jcoff)\
**Post date:** [August 20, 2010, 3:30pm UTC](https://forums.plex.tv/t/xpath-confusion/4429/3 "2010-08-20T15:30:01Z")

</div>

> [@](#):
>
> xpath() will always return a list, even if there's only one item - item.xpath('.h1')[0].text would probably work.

  
  
Yay, that fixed that. Thank you. Now to get the vids to play...

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [December 20, 2019, 8:41pm UTC](https://forums.plex.tv/t/xpath-confusion/4429/4 "2019-12-20T20:41:08Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
