# Xpath question

**URL:** <https://forums.plex.tv/t/xpath-question/104091>\
**Category:** Dev/API Corner\
**Tags:** plugin-dev\
**Created:** [May 24, 2015, 8:41pm UTC](https://forums.plex.tv/t/xpath-question/104091 "2015-05-24T20:41:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![eetjtl](https://avatars.discourse-cdn.com/v4/letter/e/ed655f/32.png) [@eetjtl](https://forums.plex.tv/u/eetjtl)\
**Post date:** [May 24, 2015, 8:41pm UTC](https://forums.plex.tv/t/xpath-question/104091/1 "2015-05-24T20:41:40Z")

</div>

There is an older/abandoned channel that has a portion broken.  
I narrowed it down to this  
  
name = channel.xpath(’.//strong’)[0].text  
  
and then further down in code it puts it in a list  
  
It’s trying to pull channel name between multiple class=‘play’\> **CNBC**  
 . class=‘play’\> **ABC**  
  
, etc  
But in the mix of the html scrape are a few

**…**
  
  
So it errors out when it tries to add … to the list.  
Any ideas on how better code this ?

---

<div class="post-metadata">

**Author:** ![czukowski](https://sea1.discourse-cdn.com/plex/user_avatar/forums.plex.tv/czukowski/32/9008_2.png) [@czukowski](https://forums.plex.tv/u/czukowski)\
**Post date:** [May 27, 2015, 4:12pm UTC](https://forums.plex.tv/t/xpath-question/104091/2 "2015-05-27T16:12:53Z")

</div>

I'd try ".//div[@class='play']/strong" but this may or may not work depending on what element is in the channel variable. I also assumed the element with class='play' is div, if it's not, edit the expression accordingly or use asterisk (\*) to match any tag name.

---

<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 29, 2015, 5:25pm UTC](https://forums.plex.tv/t/xpath-question/104091/3 "2015-05-29T17:25:16Z")

</div>

You can check the value the xpath query finds and continue the loop if the value is "...".

```
name = channel.xpath('.//strong')[0].text

if name == “…”:  
&nbsp; &nbsp; continue
```

---

<div class="post-metadata">

**Author:** ![eetjtl](https://avatars.discourse-cdn.com/v4/letter/e/ed655f/32.png) [@eetjtl](https://forums.plex.tv/u/eetjtl)\
**Post date:** [May 29, 2015, 10:02pm UTC](https://forums.plex.tv/t/xpath-question/104091/4 "2015-05-29T22:02:50Z")

</div>

Thanks guys got it working using a mix of both.&nbsp; &nbsp;

name = page.xpath(".//a[@class='play']/strong")[n].text  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; oc.add(DirectoryObject(key = Callback(GuideSubMenu, title=name, data=String.Encode(show\_info)), title=name, thumb=R(name + '.jpg')))  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if name != "...": n = n + 1  
else: n = n + 2

---

<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:** [January 8, 2020, 7:49pm UTC](https://forums.plex.tv/t/xpath-question/104091/5 "2020-01-08T19:49:04Z")

</div>

Closed on January 8, 2020, 7:49pm UTC


