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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With