Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get an individual css style in pyquery

You can set a css style using several methods:

p = PyQuery('<p></p>')
p.css('font-size','16px')
p.css(['font-size'] = '16px'
p.css = {'font-size':'16px'}

Great, but how to get an individual css style?

p.css('font-size') # jquery-like method doesn't work
[<p>]
p.css['font-size'] # pythonic method doesn't work!
[<p>]
p.css.font_size # BeardedO's suggestion.
[<p>]
p.attr('style')    # too much information.
'font-size: 16px; font-weight: bold'

This seems strange, inconvenient and unpyquery and unpython like! One of the first two ought to return the style text, surely?

Is there a way to get a single css style alone without resorting to tools like split()?

like image 990
shafty Avatar asked Feb 16 '11 22:02

shafty


1 Answers

p.css.font_size

Does this work?

like image 167
VoronoiPotato Avatar answered Nov 14 '22 23:11

VoronoiPotato