1

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.

gasgen
  • 319
  • 1
  • 2
  • 14

1 Answers1

2

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>]
TankorSmash
  • 12,186
  • 6
  • 68
  • 106
  • thanks TankorSmash, I did not explain very well. I need the script take de name of id's in html. For example:
    content
    , the script have to give me "hello"
    – gasgen Apr 06 '13 at 18:13
  • @Benyi No problem at all! If the solution works for you, please feel free to click the checkmark near my answer to mark this question as solved. – TankorSmash Apr 06 '13 at 18:15