gpt4 book ai didi

python - 用 mechanize 填写搜索表单

转载 作者:太空宇宙 更新时间:2023-11-04 06:33:01 24 4
gpt4 key购买 nike

我正在尝试使用 mechanize 在网站上进行搜索(第一次体验这个库,我几乎不知道 html 和浏览机制)。

它可以正常登录网站,但我无法在下一页填写搜索表单。对于登录,我使用:

    from mechanize import Browser
br = Browser()
br.open(top_url)
br.select_form(nr=0)
br["login"] = username
br["password"] = password
br.submit()

然后我在表单上使用循环来查看表单字段的名称:

>>> for i in br.forms():
... print i
... break
...

这给了我这个:

<naurp_form POST https://sd.priocom.com/fx/$sd/servlet.ru.naumen.sd.search.SearcherServlet multipart/form-data
<TextControl(sdsearch_ServiceCallIdSearchType=)>
<SubmitControl(dosearchsdsearch_ServiceCallIdSearchType=>) (readonly)>
<HiddenControl(hidden_dosearchsdsearch_ServiceCallIdSearchType=) (readonly)>
<TextControl(sdsearch_ServiceCallDescriptionSearchType=)>
<SubmitControl(dosearchsdsearch_ServiceCallDescriptionSearchType=>) (readonly)>
<HiddenControl(hidden_dosearchsdsearch_ServiceCallDescriptionSearchType=) (readonly)>
<HiddenControl(searchType__exists=1) (readonly)>
<SelectControl(searchType=[ClientTitleSearchType, *ClientTitleSearchType, CrmLiteJuridicalClientContactPersonSearchType, CrmLiteByPhoneSearchType, ServiceTitleSearchType, ContractTitleSearchType, CrmLiteNaturalClientSearchType, CrmLiteJuridicalClientSearchType, SDTaskIdSearchType, SDTaskDescriptionSearchType, SDTaskIdSearchType, ServiceCallIdSearchType, ServiceCallCommentSearchType, CoreEmployeeSearchType, CoreOUSearchType, CoreEmployeeSearchType, CoreClientSearchType, CoreContractTitleSearchType, CoreServiceSearchType, KBaseSearchType, CMDBObjectTitleSearchType, CMDBObjectInvNumberSearchType])>
<TextControl(searchString=)>
<SubmitControl(doSearch=>) (readonly)>
<HiddenControl(hidden_doSearch=) (readonly)>
<HiddenControl(searchUUID=) (readonly)>
<CheckboxControl(searchInResult=[on])>
<HiddenControl(searchInResult__exists=1) (readonly)>
<HiddenControl(backURL=/fx/sd/ru.naumen.sd.published_jsp?uuid=coreboqme50d80000il15pbh3tiac13s) (readonly)>
<SubmitControl(doClear=╨Ю╤З╨╕╤Б╤В╨╕╤В╤М ╤А╨╡╨╖╤Г╨╗╤М╤В╨░╤В╤Л) (readonly)>
<HiddenControl(hidden_doClear=) (readonly)>
<HiddenControl(__form_id=searchTab.searchForm) (readonly)>
<HiddenControl(first_load=true) (readonly)>>

表格总数 = 3 (0,1,2) 与网站完全匹配的表格。我对第一种形式感兴趣,"sdsearch_ServiceCallIdSearchType"。在实际网站上,它看起来像一个字段和一个按钮“>>”,显然 dosearchsdsearch_ServiceCallIdSearchType

所以我正在尝试这个:

br.select_form(nr = 0)
br['sdsearch_ServiceCallIdSearchType'] = '2770'
#also tried br.form['sdsearch_ServiceCallIdSearchType'] = '2770'
response = br.submit("dosearchsdsearch_ServiceCallIdSearchType")
tt_page = br.response().read()

更新:还尝试了 .click() 方法

response = br.click(type = 'submit',name = "dosearchsdsearch_ServiceCallIdSearchType")
tt_page = br.response().read()

但在 tt_page 中,我仍然收到第一个搜索页面(我尝试填写搜索表单的页面)。

感谢任何提示。

PS:我需要网站上的搜索表单代码(我不知道它是什么意思。我可以猜测但不能确定我的猜测是否正确):

<!--formbutton.jsp-->
<tr id="sdsearch_ServiceCallIdSearchType_outer" >
<th style="width:25%;">
TT number
</th>
<td align="left"
style="width:100%;vertical-align:middle;">
<table border="0" cellpadding="0" cellspacing="0"><tr><td style="border:0px">
<input type="text"
id="sdsearch_ServiceCallIdSearchType"
name="sdsearch_ServiceCallIdSearchType"
size="30"
value=""
maxlength="254"
style=""
/>
</td><td style="border:0px">
<span id="dosearchsdsearch_ServiceCallIdSearchType_outer"
name="dosearchsdsearch_ServiceCallIdSearchType_outer"
><input
onclick="
mark_as_pressed(window.event, this);
"
style="margin:1px;"
type="submit"
id="dosearchsdsearch_ServiceCallIdSearchType"
name="dosearchsdsearch_ServiceCallIdSearchType"
value="&#062;"
/></span>
<input type="hidden" id="hidden_dosearchsdsearch_ServiceCallIdSearchType" name="hidden_dosearchsdsearch_ServiceCallIdSearchType"></td></tr></table></td>
</tr>

附: This post was helpfull以及该网站上的一些帖子。但是没有人告诉我为什么在我的情况下它不起作用。

仍然找不到填写该表格并转到下一页的方法。

最佳答案

br.select_form(nr = 0)
br['sdsearch_ServiceCallIdSearchType'] = '2770'
br.submit()

这应该适用于提交要搜索的表单!

关于python - 用 mechanize 填写搜索表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14728091/

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