Max*_*rai 15 python beautifulsoup find
我正在使用美丽的汤(在Python中).我有这样隐藏的输入对象:
<input type="hidden" name="form_build_id" id="form-531f740522f8c290ead9b88f3da026d2" value="form-531f740522f8c290ead9b88f3da026d2" />
Run Code Online (Sandbox Code Playgroud)
我需要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'
Run Code Online (Sandbox Code Playgroud)
我试图改变代码:
print soupHandler.find(name='form_build_id', type='hidden')
None
Run Code Online (Sandbox Code Playgroud)
怎么了?
unu*_*tbu 26
尝试使用替代attrs关键字:
areaId = soupHandler.find('input', attrs={'name':'form_build_id', 'type':'hidden'})
Run Code Online (Sandbox Code Playgroud)
您不能使用名为name的关键字参数,因为Beautiful Soup搜索方法已经定义了name参数.您也不能将Python保留字用作关键字参数.
Beautiful Soup提供了一个名为attrs的特殊参数,您可以在这些情况下使用它.attrs是一个字典,就像关键字参数一样.
| 归档时间: |
|
| 查看次数: |
5736 次 |
| 最近记录: |