在Python里打开一个网站的框架或图像 [英] Opening a website frame or image in python
问题描述
所以我相当流利使用Python和已经使用的urllib2和Cookies很多关于网站的自动化。我只是偶然发现了网页浏览器模块,可在您的默认浏览器中打开一个URL。我想知道如果可以选择从URL只是一个对象,并打开了。具体来说,我想开一个验证码,使用户可以输入它,然后继续做别的事情。
So i am fairly fluent with python and have used urllib2 and Cookies a lot for website automation. I just stumbled upon the "webbrowser" module which can open a url in your default browser. Im wondering if its possible to select just one object from that url and open that up. Specifically i want to open a "captcha" so that the user can input it, and continue doing something else.
包含在HTML中的验证码,这是行,我想:
this is line containing the captcha in the html, i think:
script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6LcZ-AAAAAAAANX-xwVtzow1f4RpSrbSViRUx9Js"></script> <input type="submit" name="submitBtn" value="Submit"
和点击该API链接,打开这样的:
and clicking on that api link opens this:
var RecaptchaState = {
site : '6LcZ-AAAAAAAANX-xwVtzow1f4RpSrbSViRUx9Js',
challenge : '03AHJ_VuvoUHPdfoXLsVHGa7a26GR9s9Y5dkyKmqk2XsJ1SdiwF_2u0SV_sKnr1artkpc-5MjUe7SYD40xr7sAyvikKwpFCQTBdKUFfl76UP6EbDhezoTC8B1X8fjixuIJ4wJhI6yTc8vlX4ioh6je9lwFbPXllbGh2w',
is_incorrect : false,
programming_error : '',
error_message : '',
server : 'http://www.google.com/recaptcha/api/',
timeout : 18000
};
document.write('<scr'+'ipt type="text/javascript" s'+'rc="' + RecaptchaState.server + 'js/recaptcha.js"></scr'+'ipt>');
任何信息将有助于这一点。
any info would help with this.
推荐答案
这是不可能的web浏览器模块。所有的web浏览器所做的是提供一个简单的方法来识别默认Web浏览器和饲料的URL给它。
It's not possible with the webbrowser module. All webbrowser does is provide a simple way to identify the default web browser and feed a URL to it.
如果你想呈现页面只是一个部分,你需要的东西,可以乘坐任意HTML片段或加载一个页面来去掉不需要的元素后,可以注入一些JavaScript。
If you want to render just a portion of a page, you need something that can either take arbitrary HTML fragments or can inject some Javascript after loading a page to strip out the unwanted elements.
对于这一点,你需要的是建立一个特定目的的Web浏览器什么比包含Web部件的对话框了。
For that, what you need is to build a purpose-specific web browser that's nothing more than a dialog box containing a web widget.
这是可以做到任何库的组合:
That can be done using any of the following combinations of libraries:
- PyQt的和包含的 QtWebKit的(GPL或商业,Windows / Mac的/ Linux)的
- PySide 和包含的 QtWebKit的(LGPL和Linux)
- PyGTK的并的 pyWebKitGTK (LGPL,容易在Linux上...没有关于Windows或OSX线索)
- PyGTK的并的 GTKMozEmbed (LGPL,容易在Linux上...没有关于Windows或OSX线索)
- 的wxPython 和包含的 wxIEHtmlWindow (BSD类似,仅Windows。嵌入功能的Internet Explorer。)
- 的wxPython 和包含的 wxWebKitCtrl (类似BSD,OSX只)
- wxPython的并的 wxWebKit (BSD类似,Windows / Mac的/ Linux)的
- PyQt and the included QtWebKit (GPL or Commercial, Windows/Mac/Linux)
- PySide and the included QtWebKit (LGPL, Linux)
- PyGTK and PyWebKitGTK (LGPL, Easy on Linux... no clue about Windows or OSX)
- PyGTK and GTKMozEmbed (LGPL, Easy on Linux... no clue about Windows or OSX)
- wxPython and the included wxIEHtmlWindow (BSD-like, Windows-only. Embeds Internet Explorer.)
- wxPython and the included wxWebKitCtrl (BSD-like, OSX-only)
- wxPython and wxWebKit (BSD-like, Windows/Mac/Linux)
我的建议是:
- 如果GPL许可证是确定的,使用PyQt的。
- 如果GPL许可是不正常:
- 对于Linux,使用PySide或PyGTK的使用PyWebKitGTK(GTKMozEmbed重)
- 对于Windows,使用wxPython中有wxIEHtmlWindow
- 对于OSX,你得问别人。
这篇关于在Python里打开一个网站的框架或图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!