Python Gets the image download address on the Web page _python

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.