作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在与一家食品银行合作,以帮助他们在有人填写摄入表格时自动为新客人创建一个条目。为了创建新客人,必须首先选择外展。这是通过作为全局表单一部分的 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'>]
此屏幕截图显示了网站的外观
最佳答案
再次查看后,我发现该站点正在根据该下拉列表的内容运行 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/
我正在与一家食品银行合作,以帮助他们在有人填写摄入表格时自动为新客人创建一个条目。为了创建新客人,必须首先选择外展。这是通过作为全局表单一部分的 ListControl 完成的。 import mec
我是一名优秀的程序员,十分优秀!