httpdream / soupselect

Automatically exported from code.google.com/p/soupselect
0 stars 0 forks source link

Changes to mimic jQuery/BeautifulSoup #3

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Attached is a small patch that will make soupselect behave more like jQuery 
and/or BeautifulSoup:

 1. attribute lookup like BeautifulSoup (like jQuery, it assumes we want 
    the attribute of the first element if there are more than one):

     soupselect.select(soup, 'h3').id   # get the id of the first h3 element

 2. respond to text() and html() like jQuery

     # print text content of first h3 tag
     soupselect.select(soup, 'h3').text() 

     # print html of first h3 tag
     soupselect.select(soup, 'h3').html() 

I put this patch in the public domain.

Original issue reported on code.google.com by BjornSte...@gmail.com on 13 Dec 2010 at 7:01

Attachments:

GoogleCodeExporter commented 9 years ago
This patch return AttributeError: 'NoneType' object has no attribute 'strip' 
when using .text()
so I just removed strip() and it worked properly.(Dont know why)
But in html like <h2>text,text,text<a href="#">link</a></h2> if I ask for 
text() it dosnt return nothing...
And something like .text(1) to show the second element instead of just first 
would be cool too....I dont know much of python if I knew i could help

Original comment by jacob.ma...@gmail.com on 17 Sep 2012 at 6:22