我正在使用漂亮的汤(在 Python 中)。我有这样的隐藏输入对象:
<input type="hidden" name="form_build_id" id="form-531f740522f8c290ead9b88f3da026d2" value="form-531f740522f8c290ead9b88f3da026d2" />
我需要 id/value。
这是我的代码:
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'
我尝试更改代码:
print soupHandler.find(name='form_build_id', type='hidden')
None
怎么了?
最佳答案
尝试使用 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.
关于python - 查找功能的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2877114/