The example in this article tells Python how to get a picture download address on a Web page. Share to everyone for your reference. Specifically as follows:
The download address for the picture on the Web page is a paragraph in the data collection being written, and the code is as follows:
Copy Code code as follows:
#!/user/bin/python3
Import Urllib2
From Htmlparser import Htmlparser
Class Myhtmlparser (Htmlparser):
Links = []
def handle_starttag (self, Tag, attrs):
if tag = = "img":
If Len (attrs) = = 0:
Pass
Else
For name, value in Attrs:
If name = = "src":
Self.links.append (value)
if __name__ = = "__main__":
URI = "Http://dy.163.com/v2/article/T1374483113516/AGSNE9L000964K4O"
File = Urllib2.urlopen (URI). Read ()
# file = ' hy = Myhtmlparser ()
Hy.feed (file)
Hy.close ()
Print (hy.links)
I hope this article will help you with your Python programming.