Python virgins: Download Fonts

Source: Internet
Author: User

I just started to learn python. In this era, it is worthwhile to let scripts replace people to do something.

Download it. Help me download all the fonts on a website...

Import urllibfrom sgmllib import sgmlparserclass urllister (sgmlparser): def reset (Self): sgmlparser. reset (Self) self. URLs = [] def start_a (self, attrs): href = [V for K, V in attrs if k = 'href 'and v.endswith('.zip')] If href: Self. URLs. extend (href) exts = 'a, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, q, R, S, T, U, V, W, X, Y, Z, no 'urls = ['HTTP: // www.3lian.com/ziti/zt2/fonts-' + ele + '.htm' for ele in exts. split (',')] DownLoadURL = [] for URL in URLs: HTTP = urllib. urlopen (URL) htmlsrc = http. read () HTTP. close () parser = urllister () parser. feed (htmlsrc) parser. close () DownLoadURL. extend (parser. URLs) DownLoadURL = ['HTTP: // www.3lian.com/ziti/zt2/' + ele for ele in DownLoadURL] For URL in DownLoadURL: filename = 'd: \ tddownload \ font-en \ '+ URL. split ('/') [-1] print filename zipfile = open (filename, 'wb') print 'Download --- '+ url http = urllib. urlopen (URL) zipfile. write (HTTP. read () HTTP. close () zipfile. close

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.