【问题标题】:How to save picture streams from the internet?如何保存来自互联网的图片流?
【发布时间】:2019-01-21 08:47:54
【问题描述】:

我想自动从使用流的网络源下载图片,编码为Base 64 字符串。 我的Google Chrome 浏览器将源中的数据正确识别为JPG 图片并显示出来。

现在,此页面仅供注册用户访问。在这种情况下我应该使用Selenium 吗?

所以,基本上,我想生成大约 1000 个url 请求并将所有流式传输的图片保存在我的本地磁盘上。

我请求的 URL 示例:

https://ia800703.us.archive.org/BookReader/BookReaderImages.php?zip=/10/items/nortonreaderan6theast/nortonreaderan6theast_jp2.zip&file=nortonreaderan6theast_jp2/nortonreaderan6theast_1257.jp2&scale=1&rotate=0

响应是带有图片的html 文档:

<html>
<head>
<meta name="viewport" content="width=device-width, minimum-scale=0.1">
<title>BookReaderImages.php (2447×4005) </title>
</head>
<body style="margin: 0px; background: #0e0e0e;">
<img style="-webkit-user-select: none;cursor: zoom-in;" src="https://ia800703.us.archive.org/BookReader/BookReaderImages.php?zip=/10/items/nortonreaderan6theast/nortonreaderan6theast_jp2.zip&file=nortonreaderan6theast_jp2/nortonreaderan6theast_1257.jp2&scale=1&rotate=0" width="556" height="911">
</body>
</html>

图片流是Base 64字符串。 浏览器允许保存为nortonreaderan6theast_1257.jpg

有什么建议吗?

【问题讨论】:

  • 没有。它不是重复的。在我的情况下,您不能使用快照。图像大小为 2447×4005,并调整大小以适合屏幕显示。正如你所看到的,图像源并不直接指向图片。我怀疑处理此流的最简单方法是使用Chrome dev-tools API。但我不确定。

标签: selenium web-scraping google-chrome-devtools selenium-chromedriver


【解决方案1】:

我设法实施了一个可行的解决方案,尽管远非理想。 为此,我使用了 Seleniumchromedriver 和 Chrome 扩展程序 Click and Save。 首先,一旦浏览器实例启动,我必须手动安装扩展。之后,我登录一个网站,打开一本我要下载的书。每次创建新实例时,我都必须执行这些步骤。

在我使用的所有页面(url)的循环中:

    driver.get(url) # Selenium method
    ''' Click and Save extension automatically detects the picture and saves it to Downloads directory (or other) in Windows OS'''
    while not os.path.exists(file_path): # wait till the file has been created
            time.sleep(0.5)

总的来说,这个过程非常缓慢,1 小时大约 1000 页。 欢迎任何改进。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多