Python的机械化提交按钮对NIH网站 [英] Python Mechanize Submit Button on NIH Website

查看:126
本文介绍了Python的机械化提交按钮对NIH网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用机械化的蟒蛇2.7.3。我正在寻找在击中rel=\"nofollow\"> NIH的基因网站在

I'm using mechanize on python 2.7.3. I'm looking for help on hitting the submit button on NIH's gene website.

按钮是div的,而不是内部的任何形式的现场环绕的实际的按钮元素。

The button is an actual button element surrounded by divs and not inside any form field.

<button id="search" type="submit" class="button_search nowrap" cmd="go">Search</button>

因此​​,在例子和我所见过的在线到目前为止,提交按钮通常有哪些机械化可以选择,或者是在窗体名称或标签,这样我可以做br.submit()。

So far in examples and what I've seen online, submit buttons usually have a name or a label which mechanize can select for, or are in a form so I can do br.submit().

我怎么会打提交关于这一个?

How would I hit submit on this one?

感谢

推荐答案

按钮不能提交直接,而是触发JavascriptEvent,最终将加载搜索页面。这就解释了为什么按钮,您的浏览器的工作原理,即使它是不是形式中。

The button does not submit the for directly, but instead triggers a JavascriptEvent, which will eventually load the search page. This explains why the button works in your browser even though it is not inside the form.

机械化无法运行JS code,所以你不能够点击按钮直接使用机械化

mechanize cannot run JS code, so you will not be able to "click" on the button directly using mechanize.

有一个原因,你不能只是打开目标网址?这些似乎pretty简单,甚至在高级搜索表单,例如:

Is there a reason you cannot just open the target URL? These seem pretty straightforward, even on the advanced search form, for example:

term = '("31"[Chromosome]) AND "000"[Disease/Phenotype]'
q = urllib.urlencode({'term': term})
response = mechanize.urlopen('http://www.ncbi.nlm.nih.gov/gene?%s' % q)

如果这不会为你工作,你就必须依傍其不支持JavaScript的解决方案,看的的Watir VS硒VS SAHI公司了解指针。

If this does not work for you, you'll have to fall back on a solution which does support JavaScript, see Watir vs Selenium vs Sahi for pointers.

这篇关于Python的机械化提交按钮对NIH网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆