views:

35

answers:

1

Hello, I'm using beautiful soup (in Python). I have such hidden input object:

<input type="hidden" name="form_build_id" id="form-531f740522f8c290ead9b88f3da026d2" value="form-531f740522f8c290ead9b88f3da026d2"  />

I need in id/value.

Here is my code:

mainPageData = cookieOpener.open('http://page.com').read()
soupHandler = BeautifulSoup(mainPageData)

areaId = soupHandler.find('input', name='form_build_id', type='hidden')

TypeError: find() got multiple values for keyword argument 'name'

I tried to change code:

print soupHandler.find(name='form_build_id', type='hidden')
None

What's wrong?

+3  A: 

Try using the alternative attrs keyword:

areaId = soupHandler.find('input', attrs={'name':'form_build_id', 'type':'hidden'})

You can't use a keyword argument called name because the Beautiful Soup search methods already define a name argument. You also can't use a Python reserved word like for as a keyword argument.

Beautiful Soup provides a special argument called attrs which you can use in these situations. attrs is a dictionary that acts just like the keyword arguments.

unutbu