# need help with xpaths

**URL:** <https://forums.plex.tv/t/need-help-with-xpaths/9323>\
**Category:** Dev/API Corner\
**Tags:** plugin-dev\
**Created:** [May 18, 2011, 1:02am UTC](https://forums.plex.tv/t/need-help-with-xpaths/9323 "2011-05-18T01:02:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![41john](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/41john/32/493_2.png) [@41john](https://forums.plex.tv/u/41john)\
**Post date:** [May 18, 2011, 1:02am UTC](https://forums.plex.tv/t/need-help-with-xpaths/9323/1 "2011-05-18T01:02:17Z")

</div>

trying to work on my second plugin, this will be the first using xpaths can someone please help me?  
  
  
  
Here is an example page  
  
  
  
[http://www.nfl.com/videos/new-orleans-saints](http://www.nfl.com/videos/new-orleans-saints)  
  
  
  
If I wanted to get the titles: Bush’s future in New Orleans, No joke: Bush’s tweets offend fans, Saints’ draft evaluation from that page what xpath would i use?  
  
same question for the corresponding url, subtitle, and image.  
  
  
  
If you can even explain how you figured out the xpath that would be greatly appreciated. xpaths are one thing im really stuck understanding. I try to use the firefox xpath plugin but it doesn’t really help much.

---

<div class="post-metadata">

**Author:** ![sander1](https://avatars.discourse-cdn.com/v4/letter/s/4bbf92/32.png) [@sander1](https://forums.plex.tv/u/sander1)\
**Post date:** [May 18, 2011, 2:17am UTC](https://forums.plex.tv/t/need-help-with-xpaths/9323/2 "2011-05-18T02:17:15Z")

</div>

Hello John!  
  
  
  
You can loop over:

```auto

//div[@id="videos-list"]/ul[@class="list-items"]/li

```

  
then use \*\*.//h3\*\* for title, \*\*.//h3/a\*\* for the link, \*\*.//p[@class="date"]\*\* for the date, \*\*.//p[last()]\*\* for summary and \*\*.//a/img\*\* for the thumbnail:  
  

```auto

for video in HTML.ElementFromURL("http://www.....", errors='ignore').xpath('//div[@id="videos-list"]/ul[@class="list-items"]/li'):<br />
    title = video.xpath('.//h3')[0].text<br />
    url = video.xpath('.//h3/a')[0].get('href')<br />
    date_text = video.xpath('.//p[@class="date"]')[0].text<br />
    summary = video.xpath('.//p[last()]')[0].text<br />
    thumb_url = video.xpath('.///a/img')[0].get('src')<br />
<br />
    ...<br />
    ...<br />

```

  
  
To figure out what part of the HTML page you need, you check out the source of a webpage, find the element you need and then follow the DOM tree upwards.

---

<div class="post-metadata">

**Author:** ![41john](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/41john/32/493_2.png) [@41john](https://forums.plex.tv/u/41john)\
**Post date:** [May 18, 2011, 2:26pm UTC](https://forums.plex.tv/t/need-help-with-xpaths/9323/3 "2011-05-18T14:26:29Z")

</div>

> [@](#):
>
> Hello John!  
>   
> You can loop over:  
> 
> ```auto
> 
> //div[@id="videos-list"]/ul[@class="list-items"]/li
> 
> ```
> 
>   
> then use \*\*.//h3\*\* for title, \*\*.//h3/a\*\* for the link, \*\*.//p[@class="date"]\*\* for the date, \*\*.//p[last()]\*\* for summary and \*\*.//a/img\*\* for the thumbnail:  
>   
> 
> ```auto
> 
> for video in HTML.ElementFromURL("http://www.....", errors='ignore').xpath('//div[@id="videos-list"]/ul[@class="list-items"]/li'):<br />
> title = video.xpath('.//h3')[0].text<br />
> url = video.xpath('.//h3/a')[0].get('href')<br />
> date_text = video.xpath('.//p[@class="date"]')[0].text<br />
> summary = video.xpath('.//p[last()]')[0].text<br />
> thumb_url = video.xpath('.///a/img')[0].get('src')<br />
> <br />
> ...<br />
> ...<br />
> 
> ```
> 
>   
>   
> To figure out what part of the HTML page you need, you check out the source of a webpage, find the element you need and then follow the DOM tree upwards.

  
  
Thanks sander1, this didn't quite work for me, but with a bit of tinkering with it I have it working. Many thanks for pointing me in the right direction. Biggest problem before i posted yesterday was getting it to loop and bring in each video, rather than just the first result.

---

<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, 9:08pm UTC](https://forums.plex.tv/t/need-help-with-xpaths/9323/4 "2019-12-20T21:08:23Z")

</div>

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