在html中怎么写一个下载指定位置的图片

在html中怎么写一个下载指定位置的图片,第1张

<a href="picName.jpg" id=pic1 onclick="savepic()return false" style="cursor:hand">点击下载</a>

<script type="text/javascript">

function savepic() {

if (document.all.a1 == null) {

objIframe = document.createElement("IFRAME")

document.body.insertBefore(objIframe)

objIframe.outerHTML = "<iframe name=a1 style='width:400pxhieght:300px' src=" + imageName.href + "></iframe>"

re = setTimeout("savepic()", 1)

}

else {

clearTimeout(re)

pic = window.open(imageName.href, "a1")

pic.document.execCommand("SaveAs")

document.all.a1.removeNode(true)

}

}

</script>

import os,re

def check_flag(flag):

regex = re.compile(r'images\/')

result = True if regex.match(flag) else False

return result

#soup = BeautifulSoup(open('index.html'))

from bs4 import BeautifulSoup

html_content = '''

<a href="https://xxx.com">测试01</a>

<a href="https://yyy.com/123">测试02</a>

<a href="https://xxx.com">测试01</a>

<a href="https://xxx.com">测试01</a>

'''

file = open(r'favour-en.html','r',encoding="UTF-8")

soup = BeautifulSoup(file, 'html.parser')

for element in soup.find_all('img'):

if 'src' in element.attrs:

print(element.attrs['src'])

if check_flag(element.attrs['src']):

#if element.attrs['src'].find("png"):

element.attrs['src'] = "michenxxxxxxxxxxxx" +'/'+ element.attrs['src']

print("##################################")

with open('index.html', 'w',encoding="UTF-8") as fp:

fp.write(soup.prettify()) # prettify()的作⽤是将sp美化⼀下,有可读性


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7044238.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-01
下一篇 2023-04-01

发表评论

登录后才能评论

评论列表(0条)

保存