I try to get all the "id" from an html file with PyQuery, but is bringing troubles...I try this:
from pyquery import PyQuery
file = open('index.html', 'r').read
jQuery = PyQuery(html)
jQuery.attr('id')
But shows nothing...
Help me please.
I'm not sure if your example code is what you're using but you're missing a few different things there, like calling read()
instead of making file
the read
method, and then you're never using it. You're also passing in html
when you never assigned anything to it.
But here's something I wrote that seems to find all elements with an id
, I tried following your names as best as I could, but I didn't want to reuse file
since that's a reserved word as far as I know:
from pyquery import PyQuery
html = open('temp.html').read()
jquery = PyQuery(html)
ids = jquery.find('[id]')
print ids
>>>[<link#screen-switcher-stylesheet>, <div#search>, <input#term.input-text>, <input#submit.input-button>]