def download_html_image(url, html, image_path):
""" ??html???? """
soup = BeautifulSoup(html, "html.parser")
imgs = soup.select("img")
for img in imgs:
src = img['src'] if not url else full_url(url, img["src"])
_, ext = os.path.splitext(src)
filename = "/{0}/{1}{2}".format(image_path, uuid.uuid1().hex, ext)
full_filename = "{0}{1}".format(current_app.root_path, filename)
filename = "{0}{1}".format(current_app.config["UPLOADIMG_HOST"], filename)
if not download_file(src, full_filename):
img['src'] = src
else:
img['src'] = filename
return unicode(soup)
评论列表
文章目录