Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import requests
from bs4 import BeautifulSoup
from datetime import date
from urllib.request import urlretrieve
y,m,d = date.today().isoformat().split('-')
url = f"http://www.macaodaily.com/html/{y}-{m}/{d}/node_2.htm"
res=requests.get(url)
res.encoding="utf-8"
soup=BeautifulSoup(res.text, "lxml")
element = soup.select_one('[usemap="#PagePicMap"]')
src = element["src"].replace("../","")
image_url = f"http://www.macaodaily.com/{src}"
extension = image_url.split('.')[-1]
print(image_url)
urlretrieve(image_url, f"macao-daily-{y}-{m}-{d}.{extension}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment