Python captures the QQ screenshot file uploaded in the blog

Source: Internet
Author: User
Tags python script
Ah, before writing blog time did not notice, some pictures with QQ to intercept, get the image file name is similar to the form of qq20120926174732-300x15.png, yesterday with the FTP backup site files found, Chinese name in FlashFXP inside display is garbled, It looks so uncomfortable, so write a Python script, crawl the entire site, and then get the picture name of each article page, and determine if it is similar to the form of qq20120926174732-300x15.png output and save the image address and the corresponding article address in the file, The file is then modified individually.

OK, here's the code for the program:

Import urllib2from BS4 Import beautifulsoupimport reimport sysreload (SYS) sys.setdefaultencoding (' utf-8 ') BaseURL = " Http://www.jb51.net/dont-worry.html "#说明下, the starting address is the address of the first article, through the page of the article you can use the BeautifulSoup module to get the address of the previous article File = open (r" e:\  123.txt "," a ") def pageloop (URL): page = urllib2.urlopen (URL) soup = beautifulsoup (page) img = soup.findall ([' img ']) if            IMG = = []: print "Current page no picture" return else:for myimg in img:link = Myimg.get (' src ') print link        Pattern = Re.compile (R ' qq\s*[0-9]*png ') badimg = pattern.findall (str (link)) if Badimg:print URL File.write (link + "\ n") file.write (url+ "\ n") def getthenextpage (URL): Pageloop (URL) page = Urllib2.urlo Pen (URL) soup = beautifulsoup (page) for Spanclass in Soup.findall (attrs={"class": "Article-nav-prev"}): #print Spanc Lass if Spanclass.find (' Article-nav-prev ')! = -1:pattern = Re.compile (R ' http://www.jb51.net/\s*html ') pageur    L = Pattern.findall (str (spanclass))  For i in Pageurl: #print i getthenextpage (i) getthenextpage (baseurl) print "The end!" File.close ()

Finally, and I have just started to do the site of the classmate said, the name of the picture is best used in digital form or English, pinyin form, or to the last want to change the trouble, so it is best to start from the beginning to develop good habits, with the correct naming norms to ask articles, pictures to name, this will be much better.

  • 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.