Qbik
Qbik

Reputation: 6157

R download svg file from webpage

From https://stooq.pl/q/?s=%5Espx&d=20181016&c=1d&t=l&a=lg&b=0

I would like to download main image with SP500 index, its img tag is :

<img src="c/?s=^spx&d=20181016&c=1d&t=l&a=lg" width="560" height="350" border="0">

so URL of SVG image alone is : https://stooq.pl/c/s=^spx&d=20181016&c=1d&t=l&a=lg

but R command :

download.file("https://stooq.pl/c/?s=^spx&d=20181016&c=1d&t=l&a=lg", "sp500.svg") # or .png

downloads file which is not rendered, is is possible to download proper file ?

Upvotes: 0

Views: 308

Answers (1)

Andersson
Andersson

Reputation: 52675

As been discussed in comments, here is the Python code to download required image (requests lib is required, but you can use any library that allows to make HTTP-requests):

import requests

with open('/path/to/sp500.png', 'wb') as f:
    f.write(requests.get('https://stooq.pl/c/?s=%5Espx&d=20181016&c=1d&t=l&a=lg').content)

Upvotes: 1

Related Questions