gpt4 book ai didi

python - 查找功能的参数

转载 作者:太空狗 更新时间:2023-10-29 17:03:18 26 4
gpt4 key购买 nike

我正在使用漂亮的汤(在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com