-2

I would want to extract the picture of the day from the following webpage https://apod.nasa.gov/apod/astropix.html using beautiful soup.

Could someone help me out with the code?

Thanks in advance!

  • Hello. Welcome to SO. Please follow the guideline while asking questions: https://stackoverflow.com/help/how-to-ask . BTW can you please be more specific about "extract". Is that getting the linked? Save the image to your disk? – tagoma Jun 28 '17 at 10:59

1 Answers1

1

install

pip install --upgrade beautifulsoup4
pip install --upgrade html5lib

Then to get the img src url you can do this.

from bs4 import BeautifulSoup
import requests
data = requests.get("https://apod.nasa.gov/apod/astropix.html").content
soup = BeautifulSoup(data)
img = soup.findAll("img")[0] # this link has only one image
src = "https://apod.nasa.gov"+img.attrs.get("src")

Remember dont ask to write code for you. first try and show us your effrot. This should be your last question like this.

To download the image you can check this answer

Swagat
  • 617
  • 5
  • 16