Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Recipes

Notices

Reply
 
Thread Tools Search this Thread
Old 11-17-2010, 06:24 PM   #1
boocko
Junior Member
boocko began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Nov 2010
Device: kindle3
keep_only_tags and findAll

Hello!

How does keep_only_tags pass parameters to soup's findAll?
Is it possible to do something as:

soup.findAll('p', limit=3)

with keep_only_tags syntax?

I want to keep only first div tag with a certain class attribute.
boocko is offline   Reply With Quote
Old 11-18-2010, 11:38 AM   #2
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Thumbs up

Quote:
Originally Posted by boocko View Post
Is it possible to do something as:
soup.findAll('p', limit=3)
with keep_only_tags syntax?
It's an interesting question, and one I don't know the answer to.

Quote:
I want to keep only first div tag with a certain class attribute.
If there's only one of them, you can define it easily without the limit, but I assume there's more than one. You can always remove_tags_after the tag of interest. Or you can preprocess_html and use findAll with the limit parameter directly.
Starson17 is offline   Reply With Quote
Advert
Old 11-18-2010, 11:50 AM   #3
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
you use a dictionary to specify keep only tags, that dictionary is converted to keyword argumets and passed to findAll, so any keyword argument findAll supports, you can use.
kovidgoyal is offline   Reply With Quote
Old 11-18-2010, 11:59 AM   #4
Starson17
Wizard
Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.Starson17 can program the VCR without an owner's manual.
 
Posts: 4,004
Karma: 177841
Join Date: Dec 2009
Device: WinMo: IPAQ; Android: HTC HD2, Archos 7o; Java:Gravity T
Quote:
Originally Posted by kovidgoyal View Post
you use a dictionary to specify keep only tags, that dictionary is converted to keyword argumets and passed to findAll
That's simple enough. Thanks for the clarification.
Starson17 is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
keep_only_tags ultimatebuster Calibre 4 03-19-2010 07:49 PM


All times are GMT -4. The time now is 12:03 AM.


MobileRead.com is a privately owned, operated and funded community.