Kodi Community Forum

Full Version: I've never write a scraper, a quick help ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Hi there !

I'm working on a tool which combine XBMC scrapper for a search, and the produce HTML rendering of the result. The idea is to be able to scrap from multiple sources (for example take thumb on imdb scraper, fanart on tmdb scraper and plot from allocine scrapper).

My tool start to make the deal (with the use of my dll to scrap from the different scraper) and produce an HTML result. What I wanna do now is writing a scraper.

Here is a little sample :

with the resquest : http://localhost:52026/CMMServer/Default.aspx?s=Basic

I have the response :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    CMM Response
    <form name="form1" method="post" action="Default.aspx?s=Basic+(2003)" id="form1">

    <table id="TableResult" border="0" style="width:133px;">

    <tr id="FanartRow">
        <td id="FanartCell"><img id="FanartImage" src="./temp/fanart_2eff675a-974c-41d8-99d7-eb371f4214ff.jpg" style="border-width:0px;" /></td>
    </tr><tr id="TableRow1">
        <td id="TableCell1"><img id="ThumbImage" src="./temp/thumb_2eff675a-974c-41d8-99d7-eb371f4214ff.jpg" style="border-width:0px;" /></td>
    </tr><tr id="TableRow2">
        <td id="TableCell2"><span id="Plot">Une nuit, lors d'un exercice d'entraînement, un ouragan frappe Panama. Six militaires dont l'autoritaire sergent West disparaissent et il ne reste que deux témoins pour raconter ce qu'il s'est passé.</span></td>
    </tr><tr id="TableRow3">
        <td id="TableCell3"><span id="Director">John McTiernan</span></td>

    </tr><tr id="TableRow4">
        <td id="TableCell4"><span id="Genre">Action / Thriller</span></td>
    </tr><tr id="TableRow5">
        <td id="TableCell5"><span id="PlotOutline">Une nuit, lors d'un exercice d'entraînement, un ouragan frappe Panama. Six militaires dont l'autoritaire sergent West disparaissent et il ne reste que deux témoins pour raconter ce qu'il s'est passé.</span></td>
    </tr><tr id="TableRow6">
        <td id="TableCell6"><span id="Runtime">1h 38min</span></td>
    </tr><tr id="TableRow7">

        <td id="TableCell7"><span id="Studio"></span></td>
    </tr><tr id="TableRow8">
        <td id="TableCell8"><span id="Tagline">On sent que les deux acteurs prennent un réel plaisir à jouer au chat et à la souris. Et nous aussi !</span></td>
    </tr><tr id="TableRow9">
        <td id="TableCell9"><span id="Title">Basic</span></td>
    </tr><tr id="TableRow10">
        <td id="TableCell10"><span id="Votes">23,325</span></td>

    </tr><tr id="TableRow11">
        <td id="TableCell11"><span id="WritingCredit"></span></td>
    </tr><tr id="TableRow12">
        <td id="TableCell12"><span id="Rating">6,3</span></td>
    </tr><tr id="TableRow13">
        <td id="TableCell13"><span id="Year">2003</span></td>



But I'm not strong enought to write the scraper (I'm not very fluent with regexp). Does anyone can help me ?
uhrr. read the scrapers. pretty much EVERY scraper grabs info from several sites.
Hi spiff,

Never the less, my tool produce this kind of HTML and I need to scrap this result.
then it's time to learn regexp Wink

why don't you make your local service output the xbmc xml format? then a scraper is dead simple...
Don't you think it's a bit odd to come here and ask other people to implement a scraper for you that they don't even benefit from.

Why don't you just start reading how to build your own scraper and try the editor that you can find here.

It only took me 1 day to build my own scraper beginning with completly no knowledge at all.

Its really beginner friendly and at the end it even was fun.
In fact, my little tool has his own database. In fact, I have a form to configure the scraping. Then, I scrap and store data in a database. At least I have another form to let the user select a specific Fanart and a specific thumb for each movie.

Then I've wrote a simple web app to retrieve data from the database in a simple page.

What you're saying is XBMC store media info internally in XML and you suggest me to get this XML ?


Hi, and sorry, to borry you with my question. It was just to gain time in my dev. It's a good idea to use the editor I haven't think of it, thanks for the idea.
no, i mean have that web page you wrote generate xml instead of html.
Hmm, yes why not, but where it should be be easier to scrap ?
(Ok, I understand not a lot in scraper in fact Rolleyes I've just make a dll from the xbmc code to scrap, that's all)
because you don't need to scrape that way - you just pass the entire results on

<GetDetails dest="3">
           <RegExp input="$$1" output="\1" dest="3">
              <expression noclean="1"/>

and you're done
How can I know the XML format I have to produce ? (I have to go now, I will take a look in this way tomorrow)
Ok, I will read this tomorrow spiff, thanks for your help. My tool is in early alpha (UI is very bad for now Smile) I will publish it when it will be cleaner Smile
spiff Wrote:then it's time to learn regexp Wink

regex isn't hard... hell no!

M4 now we're talking hard... Try simply reading an 'ordinary' sendmail.cf file and then explain what its doing... yea the people responsible for that must have been one "very special high" when they wrote that stuff...

Okay lets get serious!

Thats not to say that the above comments are in any way an exaggeration... They're not. They are quite serious and accurate. Big Grin

regex isn't THAT hard so much as it can be picky... not all regex are created equal and depending on the version adopted by the developer (in this case the XBMC developers) you might see some minor variations in syntax when you're trying to learn it.

I'd say a good generic place to start learning regex is:


Its very basic but it will start your brain thinking in a 'regex' mindset.

It might seem daunting but little by little you'll begin to see certain character sequences and say AH I know what thats searching for and then again you'll see long and very elegant I might add regex sequences and say WTFreak could they possibly be looking for. lol

Before diving in too deep into the tutorial I linked you might want to first find out what regex they have adopted in XBMC and then look for a tutorial based specifically on that variant so you don't learn too many 'wrong' things.


heh, true. but you need nowhere those skills to do simple selections which is what writing a scraper takes
It's not the first time I have to fight with regex in my work, but I really hate that Smile But Thanks DaveGee, I will take a look at your link and try make effort to understand regex a little more Smile

so spiff, if I understand well, all I have to do is generate this kind of XML :


I am right ? I can't see where to put fanarts in this xml...
Pages: 1 2 3