need help with python syntax

H

homepricemaps

if i have a piece of html that looks like this

<tr class="rulesbody">
<td width="183" class="rulesbody">cnn.com

and i want to scrape out cnn.com , what syntax would i use? i have
tried this and it doesn't work

for incident in bs('td', {'class' : 'rulesbody'}, {'class' :
'rulesbody'} ):
 
G

gene tani

if i have a piece of html that looks like this

<tr class="rulesbody">
<td width="183" class="rulesbody">cnn.com

and i want to scrape out cnn.com , what syntax would i use? i have
tried this and it doesn't work

for incident in bs('td', {'class' : 'rulesbody'}, {'class' :
'rulesbody'} ):

Did you try Beautiful soup, as suggested in the reply you got the 1st
time you posted this question?
 
G

gene tani

gene said:
Did you try Beautiful soup, as suggested in the reply you got the 1st
time you posted this question?

sorry, nevermind, you did put forth some effort

myhtml=r'<tr class="rulesbody"> <td width="183"
class="rulesbody">cnn.com </td>'
soup = BeautifulSoup(myhtml)
print soup.td.string
 
M

Mike Meyer

if i have a piece of html that looks like this
<tr class="rulesbody">
<td width="183" class="rulesbody">cnn.com
and i want to scrape out cnn.com , what syntax would i use? i have
tried this and it doesn't work
for incident in bs('td', {'class' : 'rulesbody'}, {'class' :
'rulesbody'} ):

If you're using BeautifulSoup, you don't need to pass in the second
dictionary. For that matter, you don't need to pass in the first one -
bs.fetch (which is what calling a tag object calls) will treat a
bare string as a request for a class. On the other hand, I don't like
using the callable objecdt shortcut, and prefer spelling out fetch
explicitly. So you'd write:

for incident in bs.fetch('td', 'rulesbody'):

<mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,311
Members
47,986
Latest member
ColbyG935

Latest Threads

Top