gpt4 book ai didi

python - 如何使用 mechanize (python) 在 global_form ListControl 元素中进行选择?

转载 作者:行者123 更新时间:2023-12-04 16:21:07 24 4
gpt4 key购买 nike

我正在与一家食品银行合作,以帮助他们在有人填写摄入表格时自动为新客人创建一个条目。为了创建新客人,必须首先选择外展。这是通过作为全局表单一部分的 ListControl 完成的。

import mechanize
import http.cookiejar

br = mechanize.Browser()
cj = http.cookiejar.LWPCookieJar()
br.set_cookiejar(cj)
br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
br.addheaders = [('User-agent', 'Chrome')]


# login

br.open('https://companywebsite.com/login')
br.select_form(nr = 0)
br.form['username'] = 'my_username'
br.form['password'] = 'my_password'
br.submit()


# Deselect the default placeholder value and select the name of the outreach

br.open('https://companywebsite.com/create-new-visit')
br.global_form().find_control(id='outreachSelect').items[0].selected = False
br.global_form().find_control(id='outreachSelect').items[1].selected = True
print(br.global_form().find_control(id='outreachSelect').items)
这是我得到的输出。如您所见,第一项仍处于选中状态。
[<Item name='0' id=None value='0' selected='selected' contents='Select an Outreach' label='Select an Outreach'>, 
<Item name='558' id=None value='558' contents='Company Name' label='Company Name'>]
此屏幕截图显示了网站的外观
This screenshot shows how the website looks
为了使“创建新访客”按钮起作用,必须更改“选择外展”下拉菜单

最佳答案

再次查看后,我发现该站点正在根据该下拉列表的内容运行 javascript。 When the correct option was selected it would make a request to https://companywebsite.com/create-new-visit/set-outreach/?id=config_1 .

通过使用 mechanize 发出相同的请求,然后使用“创建新访客”按钮,我能够解决我的问题。

关于python - 如何使用 mechanize (python) 在 global_form ListControl 元素中进行选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60903420/

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