按网页按钮 [英] Pressing A Webpage Button

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

问题描述

如何让Python按下网页上的按钮?我查看了

urllib,但我只看到如何用它打开一个URL。我搜索了

谷歌但没有运气。


例如,谷歌有一个按钮< input type = submit value =" Google

搜索命名= btnG>我如何制作一个脚本按下那个按钮?


只是为了好玩,有没有办法相当于输入一个

文本字段就好了在点击按钮之前的谷歌搜索字段?

(我实际上并不需要这样做。)


如果有人可以指出我在右边我们将不胜感激。


- 艾略特神庙
http://www.curi.us/

---

[此电子邮件通过Declude Virus扫描病毒]

How do I make Python press a button on a webpage? I looked at
urllib, but I only see how to open a URL with that. I searched
google but no luck.

For example, google has a button <input type=submit value="Google
Search" name=btnG> how would i make a script to press that button?

Just for fun, is there any way to do the equivalent of typing into a
text field like the google search field before hitting the button?
(I don''t actually need to do this.)

If someone could point me in the right direction it''d be appreciated.

-- Elliot Temple
http://www.curi.us/
---
[This E-mail scanned for viruses by Declude Virus]

推荐答案

Elliot Temple写道:
Elliot Temple wrote:
如何让Python按下网页上的按钮?我看了一下
urllib,但我只看到如何用它打开一个URL。我搜索了谷歌但没有运气。
How do I make Python press a button on a webpage? I looked at
urllib, but I only see how to open a URL with that. I searched
google but no luck.




查看机械化: http://wwwsearch.sourceforge.net/mechanize/

-

Brian Beck

第一顺序的冒险家



Check out mechanize: http://wwwsearch.sourceforge.net/mechanize/

--
Brian Beck
Adventurer of the First Order


你真的需要''按''按钮吗?或者你只需​​按下按钮会带来的

效果(例如,提交一个

Google搜索查询并收到结果页面)?


如果是后者,那么你可能想要搜索,例如html form get

post并查看一些结果。按下按钮通常只是

加载带参数的URL。


例如,转到Google并输入html form get post;进入搜索

框并按提交。现在查看您在

位置栏中访问的网址,即搜索结果的网址。它将类似于:

http://www.google.com/search?hl=en&q...=Google+Search


如果您要直接加载该网址(没有转到

Google主页,请在文字输入框中输入html表格获取帖子并按

按提交)将发生完全相同的效果。在框中填写

并单击提交按钮只是构建该URL的用户友好方式



Do you actually need to ''press'' the button? Or do you just need the
effect that pressing the button would bring about (e.g., submitting a
Google search query and receiving the results page)?

If the latter, then you might want to search for, e.g., "html form get
post" and check out some results. Pushing the button is often just
loading a URL with parameters.

For example, go to Google and type "html form get post" into the search
box and press Submit. Now look at the URL you are visiting in your
location bar, the URL of the search results. It will be something like:

http://www.google.com/search?hl=en&q...=Google+Search

If you were to load that URL directly (without having gone to the
Google homepage, typed "html form get post" in the text entry box and
pressed submit) the exact same effect would happen. Filling in the box
and clicking the submit button is just the user-friendly way of
constructing that URL.


" Elliot Temple" <铜** @ curi.us>在留言中写道

新闻:ma ************************************ ** @ pyth on.org ...
"Elliot Temple" <cu**@curi.us> wrote in message
news:ma**************************************@pyth on.org...
如何让Python按下网页上的按钮?我看了一下
urllib,但我只看到如何用它打开一个URL。我搜索了谷歌但没有运气。

例如,谷歌有一个按钮< input type = submit value =" Google
Search"命名= btnG>我如何制作一个脚本来按下那个按钮?

只是为了好玩,有没有办法在按下按钮之前输入像谷歌搜索字段这样的
文本字段?
(我实际上并不需要这样做。)
How do I make Python press a button on a webpage? I looked at
urllib, but I only see how to open a URL with that. I searched
google but no luck.

For example, google has a button <input type=submit value="Google
Search" name=btnG> how would i make a script to press that button?

Just for fun, is there any way to do the equivalent of typing into a
text field like the google search field before hitting the button?
(I don''t actually need to do this.)




你不知道哪个操作系统...如果你是你在Windows上运行IE

可以使用COM如下...


来自win32com.client import Dispatch

来自导入时间睡觉


ie = Dispatch(InternetExplorer.Application)

ie.Visible = 1

ie.Navigate(" ; http://www.google.com")

而ie.ReadyState!= 4:#等待浏览器完成加载。

sleep(1)

doc = ie.Document

doc.fqvalue =" qwerty" #form name是''f'';搜索字段名称为''q''

doc.f.btnG.click()#点击按钮''btnG''



You don''t say which OS... if you''re running IE on Windows you
can use COM as follows...

from win32com.client import Dispatch
from time import sleep

ie = Dispatch("InternetExplorer.Application")
ie.Visible = 1
ie.Navigate("http://www.google.com")
while ie.ReadyState != 4: # Wait for browser to finish loading.
sleep(1)
doc = ie.Document
doc.f.q.value = "qwerty" # form name is ''f''; search field name is ''q''
doc.f.btnG.click() # click on button ''btnG''


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

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