在Python中从URL中提取GIF图像(只返回string?)

2024-05-26 20:45:56 发布

您现在位置:Python中文网/ 问答频道 /正文

首先,有很多关于从URL中提取gif的相关问题,但是大多数问题都是用Python的不同语言编写的。第二,提供了许多类似lxoupa解析器的例子,用以美化lxoupa的请求。但是,我的问题是特定于这个URL的,我不能很好地理解为什么有问题的图像没有附加特定的URL(http://cactus.nci.nih.gov/chemical/structure/3-Methylamino-1-%28thien-2-yl%29-propane-1-ol/image

这就是我试过的

molecule_name = "3-Methylamino-1-(thien-2-yl)-propane-1-ol"
molecule = urllib.pathname2url(molecule_name)
response = requests.get("http://cactus.nci.nih.gov/chemical/structure/"+ molecule+"/image")
response.encoding = 'ISO-8859-1'
print type(response.content)

我刚拿回来一根线,上面写着GIF87au。我知道这与GIF的二进制格式有关,但我不太清楚如何使用脚本在特定页面中加载GIF文件。在

此外,如果我成功地下载了GIF文件,那么在最后一列中嵌入GIF文件来制作表格(csv或excel样式)的最佳模块是什么?在


Tags: 文件httpurlresponsestructuregifgovmolecule
1条回答
网友
1楼 · 发布于 2024-05-26 20:45:56

据我所知,你的代码对我有用。在

molecule_name = "3-Methylamino-1-(thien-2-yl)-propane-1-ol"
molecule = urllib.pathname2url(molecule_name)
response = requests.get("http://cactus.nci.nih.gov/chemical/structure/"+molecule+"/image")
response.encoding = 'ISO-8859-1'
print len(response.content)

输出“1080”。在

至于手头的第二个任务。。。把它写进文件里。我会像这样使用xlsxwriter:

^{pr2}$

http://xlsxwriter.readthedocs.org/index.html

您必须将.gif转换为.png,因为目前xlsxwriter不支持gif(正如jmcnamara指出的)。在这里您可以看到如何使用PIL-How to change gif file to png file using python pil。在

可以使用多种方法显示gif。我会把它保存到文件中,然后用其他软件。如果您想以编程方式查看它们,可以使用例如这里使用的TkinterPlay Animations in GIF with Tkinter。在

相关问题 更多 >

    热门问题