# How to save images from internet to file

**URL:** <https://discourse.julialang.org/t/how-to-save-images-from-internet-to-file/91639>\
**Category:** General Usage\
**Created:** [December 14, 2022, 12:21pm UTC](https://discourse.julialang.org/t/how-to-save-images-from-internet-to-file/91639 "2022-12-14T12:21:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![edas](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@edas](https://discourse.julialang.org/u/edas)\
**Post date:** [December 14, 2022, 12:21pm UTC](https://discourse.julialang.org/t/how-to-save-images-from-internet-to-file/91639/1 "2022-12-14T12:21:16Z")

</div>

Hi,

I want to save image from internet to file. I cannot find image related information.

Below is my example to get page and extract image block.  
Example site is my own site, using free theme.

```julia
using HTTP, Gumbo, Cascadia

url = "http://www.webkurimas.online/demo2/"

r = HTTP.get(url)

h = parsehtml(String(r.body))

body = h.root[2]

images = eachmatch(Selector("img"), body)

images[5]

```

REPL:  
HTMLElement{:img}:

So I want to save image  
[http://www.webkurimas.online/demo2/wp-content/uploads/2020/06/black-wooden-coffee-table-near-white-couch-1.jpg\_](http://www.webkurimas.online/demo2/wp-content/uploads/2020/06/black-wooden-coffee-table-near-white-couch-1.jpg_)  
to file.

I added dash to file name to prevent image to show here.

Thanks,  
Edvard

---

<div class="post-metadata">

**Author:** ![barucden](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barucden/32/26154_2.png) [@barucden](https://discourse.julialang.org/u/barucden)\
**Post date:** [December 14, 2022, 12:30pm UTC](https://discourse.julialang.org/t/how-to-save-images-from-internet-to-file/91639/2 "2022-12-14T12:30:39Z")

</div>

Get the image URL:

```julia
img_attrs = attrs(img)
img_src = img_attrs["src"]

```

Then download it:

```julia
using Downloads
download(img_src, "img.jpg")

```

This might help to get you started?

---

<div class="post-metadata">

**Author:** ![edas](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@edas](https://discourse.julialang.org/u/edas)\
**Post date:** [December 14, 2022, 12:49pm UTC](https://discourse.julialang.org/t/how-to-save-images-from-internet-to-file/91639/3 "2022-12-14T12:49:40Z")

</div>

Yes it helped !  
Thank you very much for quick answer !

---

<div class="post-metadata">

**Author:** ![edas](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@edas](https://discourse.julialang.org/u/edas)\
**Post date:** [December 14, 2022, 12:55pm UTC](https://discourse.julialang.org/t/how-to-save-images-from-internet-to-file/91639/4 "2022-12-14T12:55:47Z")

</div>

Last lines of code if someone would need:

```julia
img_link = images[5].attributes["src"]

img_name = split(img_link, '/')[end]

download(img_link, img_name)

```
