Need some help on parsing a file
#1
hi, i am trying to get startet on programming with python...

implementing and changing available scripts around a bit is working out alright for me.. but now i am trying to get startet on some own stuff.

could one of you crazy pathon gurus just help me get startet on some things.. for example.. lets say i want to read in a html file that lays on http://www.blah.com/blah.html and  display the data thats within a table in that file on xbmc.. lets say the html file looks like this:

Quote:<html>
<head>
<title>test</title>

</head>

<body>

<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>collumn 1</td><td>collumn 2</td><td>collumn 3</td><td>collumn4</td></tr>
<tr>
<td>row 2 1</td><td>row 2 2</td><td>row 2 3</td><td>row 2 4</td></tr>
<tr>
<td>row 3 1</td><td>row 3 2</td><td>row 3 3</td><td>row 3 4</td></tr>
<tr>
<td>row 4 1</td><td>row 4 2</td><td>row 4 3</td><td>row 4 4</td></tr>
<tr>
<td>row 5 1</td><td>row 5 2</td><td>row 5 3</td><td>row 5 4</td></tr>
<tr>
<td>row 6 1</td><td>row 6 2</td><td>row 6 3</td><td>row 6 4</td></tr>
</table>

</body>
</html>

how would i read in each row, parse it, and display it on the xbmc screen?

could one of you help me get jump startet on this.. i tried some things but it diddnt quite work out the right way, hehe.

thanks in advance
Reply
#2
im a newbie at python but maybe this can help u off till better help arrives! :d

try use regular expression to grab the lines that start with <td> and ends with </tr>

use another regular expression to replace <terms> with tabs. then just format it in a way u like?

im not sure, this aint so easy now that im looking at it lol :d
Reply
#3
i always had pproblems with those stupid regular expressions.

can someone post some sample code that would fit my example from the 1st post?
Reply
#4
xre = re.compile('^<td>(.*)</tr>')
p = re.compile( '(<.*>)')

links = xre.findall(data)
for link in links:
name = p.sub (' ', link[0])

# replaces the <td> or </td> with spaces

it might work heh
Reply
#5
how do i access and open the file again?
Reply
#6
keep an eye out on the upload page :-)

i just submitted a script very similar to this (parses information from an html table and opens files).

should be there tomorrow.

to do file stuff though you do

Quote:f = open(filename,'r')
stringline = f.readline()
f.close()
...
os.remove(filename)
...
f = open(filename,'w')
f.write("written to a file")
f.close()

-asteron
Reply
#7
great.. sounds great.

i'll check it out.

thanks to both of you :thumbsup:
Reply

Logout Mark Read Team Forum Stats Members Help
Need some help on parsing a file0