Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parameters for find function

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?

like image 360
Max Frai Avatar asked May 20 '10 19:05

Max Frai


People also ask

How do you use the Find function in an array?

JavaScript Array find()The find() method returns the value of the first element that passes a test. The find() method executes a function for each array element. The find() method returns undefined if no elements are found. The find() method does not execute the function for empty elements.

What are the function parameter rules?

Function Parameters are the names that are define in the function definition and real values passed to the function in function definition are known as arguments. Parameter Rules: There is no need to specify the data type for parameters in JavaScript function definitions.

Can a function parameter be a function?

Function Parameters and ArgumentsFunction parameters are the names listed in the function definition. Function arguments are the real values passed to (and received by) the function.


1 Answers

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.

like image 99
unutbu Avatar answered Oct 12 '22 13:10

unutbu