gpt4 book ai didi

Python - Mechanize 表单中的输入文本

转载 作者:行者123 更新时间:2023-11-28 17:39:11 24 4
gpt4 key购买 nike

我想在表单的文本字段中输入一些文本。这是我当前的代码。接下来我该怎么办?

import re
from mechanize import Browser

br = Browser()
br.open("xyz.com")
formcount=0
for frm in br.forms():
if str(frm.attrs["id"])=="xyz":
break
formcount=formcount+1
br.select_form(nr=formcount)

## What should I code here to input text into the form?

response = br.submit()

最佳答案

br.form['id'] = 'ss-form' # This does the input
br.submit() # This will submit the form
print br.response().read() # This will read the new page returned

尝试 print br.response().read()。这就是你想要的,你可以用 Beautiful Soup 解析响应。 soup = BeautifulSoup(br.response().read())

关于Python - Mechanize 表单中的输入文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27054550/

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