473,387 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

beutifulsoup

Hello
I try to use beautifulsoup
i have this:
sito = urllib.urlopen('http://www.prova.com/')
esamino = BeautifulSoup(sito)
luca = esamino.findAll('tr', align='center')

print luca[0]
>><tr align="center"><th width="5%"><a onclick="t('Only|G|BoT|05','#1');" href="#">#1</a></th><td width="10%">44.4MB</td><td width="90%" align="left"><font color="orange"Pc-prova.rar </font></td></tr>
I need to get the following information:
1)Only|G|BoT|05
2)#1
3)44.4MB
4)Pc-prova.rar
with: print luca[0].a.string i get #1
with print luca[0].td.string i get 44.4MB
can you explain me how to get the others two value
Thanks
Luca
Oct 29 '08 #1
5 1752
On Wed, 29 Oct 2008 09:45:31 -0700 (PDT), luca72 <lu*******@libero.itwrote:
Hello
I try to use beautifulsoup
i have this:
sito = urllib.urlopen('http://www.prova.com/')
esamino = BeautifulSoup(sito)
luca = esamino.findAll('tr', align='center')

print luca[0]
[The following long string has been wrapped.]
>>><tr align="center"><th width="5%"><a onclick="t('Only|G|BoT|05','#1');"
href="#">#1</a></th><td width="10%">44.4MB</td>
<td width="90%" align="left">
<font color="orange"Pc-prova.rar </font></td></tr>
>
I need to get the following information:
1)Only|G|BoT|05
2)#1
3)44.4MB
4)Pc-prova.rar
with: print luca[0].a.string i get #1
with print luca[0].td.string i get 44.4MB
can you explain me how to get the others two value
Like you, I struggle with BeautifulSoup; but perhaps this will help
while waiting for somebody smarter to join the thread:
>>soup = BeautifulSoup.BeautifulSoup(
.... """<tr align="center"><th width="5%">"""
.... """<a onclick="t('Only|G|BoT|05','#1');" href="#">#1</a>"""
.... """</th><td width="10%">44.4MB</td><td width="90%" align="left">"""
.... """<font color="orange"Pc-prova.rar </font></td></tr>""" )
>>tr = soup.findAll( 'tr' )
tr[0].findAll( text = True )
[u'#1', u'44.4MB', u' Pc-prova.rar ']
>>c = tr[0].findChild( attrs={"onclick": True} )
print c[ "onclick" ]
t('Only|G|BoT|05','#1');
--
To email me, substitute nowhere->spamcop, invalid->net.
Oct 29 '08 #2
Peter Pearson wrote:
Like you, I struggle with BeautifulSoup
Well, there's always lxml.html if you need it.

http://codespeak.net/lxml/

Stefan
Oct 30 '08 #3
On 29 Okt., 17:45, luca72 <lucabe...@libero.itwrote:
Hello
I try to use beautifulsoup
i have this:
sito = urllib.urlopen('http://www.prova.com/')
esamino = BeautifulSoup(sito)
luca = esamino.findAll('tr', align='center')

print luca[0]
><tr align="center"><th width="5%"><a onclick="t('Only|G|BoT|05','#1');" href="#">#1</a></th><td width="10%">44.4MB</td><td width="90%" align="left"><font color="orange"Pc-prova.rar </font></td></tr>

I need to get the following information:
1)Only|G|BoT|05
2)#1
3)44.4MB
4)Pc-prova.rar
with: print luca[0].a.string i get #1
with print luca[0].td.string i get 44.4MB
can you explain me how to get the others two value
Thanks
Luca
The same way you got `luca`

1,2) luca.find("a")["onclick"].split("'") and search through the
result list
3) luca.find("td").string
4) luca.find("font").string
Oct 30 '08 #4
hello
Another stupit question instead of use
sito = urllib.urlopen('http://www.prova.com/')
esamino = BeautifulSoup(sito)

i do
sito = urllib.urlopen('http://onlygame.helloweb.eu/')
file_sito = open('sito.html', 'wb')
for line in sito :
file_sito.write(line)
file_sito.close()

how can i pass the file sito.html to beautifulsoup?

Regards

Luca

Oct 30 '08 #5
On 30 Okt., 18:28, luca72 <lucabe...@libero.itwrote:
hello
Another stupit question instead of use
sito = urllib.urlopen('http://www.prova.com/')
esamino = BeautifulSoup(sito)

i do
*sito = urllib.urlopen('http://onlygame.helloweb.eu/')
*file_sito = open('sito.html', 'wb')
*for line in sito :
* * *file_sito.write(line)
*file_sito.close()

how can i pass the file sito.html to beautifulsoup?

Regards

Luca
download = urllib.urlopen("http://www.fiber-space.de/downloads/
downloads.html")
BeautifulSoup(download.read())

Ciao
Oct 30 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Zhang Le | last post by:
Hello, I'm writing a little Tkinter application to retrieve news from various news websites such as http://news.bbc.co.uk/, and display them in a TK listbox. All I want are news title and url...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.