New to this, troubles with XPath

Hi all,

 

I'm completely new to Plex development - there's no real walkthrough/guides out there unfortunately, but I'm determined and am having a stab at creating a plugin for the www.ddizi.org website (a website which hosts Turkish Series). A similar one exists for XBMC, but none for Plex.

 

Having trouble retrieving the XPath.

 

The link I'm trying to scrape is:

http://www.ddizi.org/yeni.eklenenler

 

and the HTML code for the titles of the series is:

 

<div class="orta-alt">

<div class="orta-orta">
<div class="four-box">
<div class="dizi-box2">
<a href="http://www.ddizi.org/izle/40641/beyaz-show-31-mayis-2013.htm" title="Beyaz Show 31 Mayıs 2013 izle">
<h1 class="liste-dizi-isim">
<a title="Beyaz Show 31 Mayıs 2013 izle" href="http://www.ddizi.org/izle/40641/beyaz-show-31-mayis-2013.htm">Beyaz Show 31 Mayıs 2013</a>
</h1>
<span class="dizi-ozet-yazi">Serdar Ortaç, Chloe Loughnan, Ebru Şallı ve Yiğit Alıcı, bu hafta “Beyaz Show”da! </span>
<span class="yorum-sayi">
</div>
<br clear="all">
</div>

 

In my MainMenu() function, I have this:

 

oc = ObjectContainer()
    
    for show in HTML.ElementFromURL(LATEST).xpath('//div[@class="dizi-box2"]'):
        title = show.xpath('./div[@class="liste-dizi-isim"]/h1/a')[0].text.strip()
    
        oc.add(DirectoryObject(key=Callback(MainMenu, title=title),title = title))

        return oc

 

When I execute this in Plex, I get empty rows. Anyone out there that can help me get over this hurdle?

 

Cheers,

Ozzie

I am pretty new to channel writing as well, but this might help.

The first part (the xpath for your loop) is good, it is the part for pulling your title that seems to be the problem. I am not sure where you got that second div command from. It should work with this instead:

title = show.xpath('./h1/a//text()')[0]

I am not sure exactly what you are wanting to do with the strip command, but I would make that a separate line like

title = title.strip()

I cannot tell you this will work for sure, since I do not have access to test it in your channel, but I just pulled up the html page you mentioned in Firefox and opened the xpath checker and pasted your two sections of xpath in there and with your commands, it gave no results, but when I entered the xpath from your for loop and the xpath that I show above it returned results. Below is the full lines that I entered in the Firefox xpath checker

your xpath that gave no matches:

 //div[@class="dizi-box2"]/div[@class="liste-dizi-isim"]/h1/a//text()

altered xpath based on the title line in the box above that gives matches:

//div[@class="dizi-box2"]/h1/a//text()

I had a hard time getting my head around the xpath at first also.  Here is a good forum post where the Mikedm139 gave me alot of help and answers that others have also said was helpful to them:

http://forums.plexapp.com/index.php/topic/49086-xpath-coding/

and here is a tutorial for to keep your xpath simpler once you get a grasp of the concepts:

http://devblog.plexapp.com/2012/11/14/xpath-for-channels-the-good-the-bad-and-the-fugly/

BTW, if you look in the forum post above (the first link), you will see a discussion on using //text() at the end of your xpath line versus .text() at the end of the line of code and why the first is better.  It does the same thing, but with the first method you can enter it exactly in the Firefox xpath checker, get the right results, and then copy and paste it directly to your channel code without having to change anything.

Wow, that worked flawlessly, thanks for the very detailed explanation!

One last question (until I get to the next hurdle), is there a way to get foreign characters to work?

i.e.. the first entry

"Tatar Ramazan 6. Bölüm 720p HD"

is meant to read

"Tatar Ramazan 6. Bölüm 720p HD"

Is that possible?

Thanks again for the reply, much appreciated

Glad that helped.

Once you have the data pulled into your channel from the site, I am guessing you would probably need to use some type of Python command to convert the language of the string. Here is a good link that has helped me understand the basics of Python strings and how you can manipulate them: http://www.tutorialspoint.com/python/python_strings.htm.

I didn't see any reference there to languages and strings, but the site gave me a basic grasp of Python string manipulation, so it may help with some of the more general concepts you need for data manipulation when writing channels. Maybe a web search of Python strings and language conversion could give you more answers. There are a lot of tutorials and answers to Python programming questions on the web, so web searches for Python commands are what I have used to figure out some of the Python code I needed to manipulate data in my channels.

But sorry, I do not know the exact commands for that. I am pretty new to channel programming, so I haven't worked with any sites that specifically required language conversion. Maybe one of the guys with more experience might be able to give you an exact command.

Thanks for that, having a look at the site now

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