need help with python syntax

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • homepricemaps@gmail.com

    #1

    need help with python syntax

    if i have a piece of html that looks like this

    <tr class="rulesbod y">
    <td width="183" class="rulesbod y">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'} ):

  • gene tani

    #2
    Re: need help with python syntax


    homepricemaps@g mail.com wrote:[color=blue]
    > if i have a piece of html that looks like this
    >
    > <tr class="rulesbod y">
    > <td width="183" class="rulesbod y">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'} ):[/color]

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

    Comment

    • gene tani

      #3
      Re: need help with python syntax


      gene tani wrote:[color=blue]
      > homepricemaps@g mail.com wrote:[color=green]
      > > if i have a piece of html that looks like this
      > >
      > > <tr class="rulesbod y">
      > > <td width="183" class="rulesbod y">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'} ):[/color]
      >
      > Did you try Beautiful soup, as suggested in the reply you got the 1st
      > time you posted this question?[/color]

      sorry, nevermind, you did put forth some effort

      myhtml=r'<tr class="rulesbod y"> <td width="183"
      class="rulesbod y">cnn.com </td>'
      soup = BeautifulSoup(m yhtml)
      print soup.td.string

      Comment

      • Mike Meyer

        #4
        Re: need help with python syntax

        homepricemaps@g mail.com writes:[color=blue]
        > if i have a piece of html that looks like this
        > <tr class="rulesbod y">
        > <td width="183" class="rulesbod y">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'} ):[/color]

        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


        --
        Mike Meyer <mwm@mired.or g> http://www.mired.org/home/mwm/
        Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

        Comment

        Working...