从 PyQt4 QtWebkit 中的网页访问图像
如果页面已完全加载到 QWebView 上,我如何获取特定图像的数据(可能通过 dom?)
If a page has fully loaded on a QWebView, how can I get the data for a certain image (probably through the dom?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会尝试尝试一下:
如果您想使用jQuery获取图像的url,您可以使用如下方法:
如果您不想每次从网络加载 jquery,您可以下载 jquery,然后像这样注入:
您也可以根本不使用 jQuery,但它通常使操作更容易,具体取决于您还想做什么。
如果你想以位图而不是url的形式获取图像内容,可以使用html画布对象,我不确定你是否会遇到跨域安全问题。
另一种方法是使用 pyQT 获取显示的图像。如果您有一个具有 alpha 透明度的 PNG,这会更复杂,但对于不透明的 JPEG,这会更容易。
您可以通过 Google 搜索一些网页屏幕截图代码来了解如何执行此操作,或者您可以从找到的 Python 网址下载。
一旦你在 Javascript 中有了 url 变量,你可能必须使用 这张很棒的幻灯片将变量放入Python中以供下载。
http://www.sivachandran.in/ index.php/blogs/web-automation-using-pyqt4-and-jquery 也可能是有用的示例代码。
I'll try taking a stab at this:
If you want to get the url of an image using jQuery you could use an approach like this:
If you didn't want to load jquery from the web each time you could download jquery then inject like this:
you could also not use jQuery at all, but it often makes manipulation easier, depending on what else you want to do.
If you want to get the image content as a bitmap not a url, it MAY be possible using a html canvas object, I'm not sure if you will run into cross-domain security problems.
Another approach would be to use pyQT to get the image as it appears. If you have a PNG with alpha-transparency, this would be more complex though, but for an opaque JPEG, for example it would be easier.
You could Google around for some webpage screenshot code for how to do that or you could download from the found url in Python.
Once you had the url variable in Javascript, you would probably have to use the cross-the-boarder technique featured on this great slideshow to get the variable into Python for downloading.
http://www.sivachandran.in/index.php/blogs/web-automation-using-pyqt4-and-jquery may be useful example code too.