在python中打开网站框架或图像 [英] Opening a website frame or image in python
问题描述
所以我相当流利的python和已经使用urllib2和饼干很多的网站自动化。我只是偶然发现了webbrowser模块,可以在默认浏览器中打开一个网址。我想知道是否可能从该URL只选择一个对象,并打开它。具体来说,我想打开一个验证码,以便用户可以输入它,并继续做别的事情。
这是包含html中的验证码的行,我认为:
script type =text / javascriptsrc =http://api.recaptcha.net/challenge?k=6LcZ-AAAAAAAANX-xwVtzow1f4RpSrbSViRUx9Js>< / script> < input type =submitname =submitBtnvalue =Submit
该api链接打开:
var RecaptchaState = {
site:'6LcZ-AAAAAAAANX-xwVtzow1f4RpSrbSViRUx9Js',
的挑战:03AHJ_VuvoUHPdfoXLsVHGa7a26GR9s9Y5dkyKmqk2XsJ1SdiwF_2u0SV_sKnr1artkpc-5MjUe7SYD40xr7sAyvikKwpFCQTBdKUFfl76UP6EbDhezoTC8B1X8fjixuIJ4wJhI6yTc8vlX4ioh6je9lwFbPXllbGh2w',
is_incorrect:假的,
programming_error:'',
ERROR_MESSAGE:'',
服务器:http://www.google .com / recaptcha / api /',
timeout:18000
};
document.write('< scr'+'ipt type =text / javascripts'+'rc ='+ RecaptchaState.server +'js / recaptcha.js> ; / scr'+'ipt>');
任何信息都有助于此。
这不可能与webbrowser模块。所有的webbrowser都提供了一个简单的方法来识别默认的web浏览器并且给它一个URL。
如果你想渲染页面的一部分,你需要它可以获取任意的HTML片段,或者可以在加载页面后注入一些Javascript来删除不需要的元素。
为此,你需要的是构建一个目的
这可以使用以下库的任何组合来完成:
- PyQt 以及所包含的 QtWebKit (GPL或商业, Windows / Mac / Linux)
- PySide 以及随附的 QtWebKit (LGPL,Linux)
- PyGTK 和 PyWebKitGTK (LGPL,Linux on Linux ...没有关于Windows或OSX的线索)
- PyGTK 和 GTKMozEmbed ( LGPL,Linux on Linux ...没有关于Windows或OSX的线索)
- wxPython 以及所包含的 wxIEHtmlWindow a>(类似BSD,仅限Windows。嵌入Internet Explorer。)
- wxPython 和所包含的 wxWebKitCtrl (类似BSD,仅限OSX)
- wxPython 和 wxWebKit (类似BSD的Windows / Mac / Linux)
p>
- 如果GPL许可正确,请使用PyQt。
- 如果GPL许可不正确:
- 对于Linux,使用PySide或PyGTK和PyWebKitGTK(GTKMozEmbed是重的)
- 对于Windows,使用wxPython with wxIEHtmlWindow
-
- 对于OSX,您必须询问其他人。
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.
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"
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.
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.
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.
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 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)
My advice:
- If GPL licensing is OK, use PyQt.
- If GPL licensing isn't OK:
- For Linux, use PySide or PyGTK with PyWebKitGTK (GTKMozEmbed is heavy)
- For Windows, use wxPython with wxIEHtmlWindow
- For OSX, you'll have to ask someone else.
这篇关于在python中打开网站框架或图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!