栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如果URL以“ blob:”开头,如何使用Python 3 / Selenium下载图像?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如果URL以“ blob:”开头,如何使用Python 3 / Selenium下载图像?

Blob是浏览器存储的原始数据的文件状对象。

您可以在以下位置看到它们

chrome://blob-internals/

可以通过脚本注入使用Selenium来获取blob的内容。但是,您必须通过在创建Blob的页面/域上运行脚本来遵守跨源策略:

def get_file_content_chrome(driver, uri):  result = driver.execute_async_script("""    var uri = arguments[0];    var callback = arguments[1];    var tobase64 = function(buffer){for(var r,n=new Uint8Array(buffer),t=n.length,a=new Uint8Array(4*Math.ceil(t/3)),i=new Uint8Array(64),o=0,c=0;64>c;++c)i[c]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(c);for(c=0;t-t%3>c;c+=3,o+=4)r=n[c]<<16|n[c+1]<<8|n[c+2],a[o]=i[r>>18],a[o+1]=i[r>>12&63],a[o+2]=i[r>>6&63],a[o+3]=i[63&r];return t%3===1?(r=n[t-1],a[o]=i[r>>2],a[o+1]=i[r<<4&63],a[o+2]=61,a[o+3]=61):t%3===2&&(r=(n[t-2]<<8)+n[t-1],a[o]=i[r>>10],a[o+1]=i[r>>4&63],a[o+2]=i[r<<2&63],a[o+3]=61),new TextDeprer("ascii").depre(a)};    var xhr = new XMLHttpRequest();    xhr.responseType = 'arraybuffer';    xhr.onload = function(){ callback(tobase64(xhr.response)) };    xhr.onerror = function(){ callback(xhr.status) };    xhr.open('GET', uri);    xhr.send();    """, uri)  if type(result) == int :    raise Exception("Request failed with status %s" % result)  return base64.b64depre(result)bytes = get_file_content_chrome(driver, "blob:https://developer.mozilla.org/7f9557f4-d8c8-4353-9752-5a49e85058f5")


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/647816.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号