Python collects QQ screenshot files uploaded from blogs,

Source: Internet
Author: User

Python collects QQ files uploaded from blogs,

And save the image address and the corresponding article address in the file, and then modify them one by one through the file.

Well, the following is the program code:

Import urllib2from bs4 import BeautifulSoupimport reimport sysreload (sys) sys. setdefaultencoding ('utf-8') baseurl = "http://www.bkjia.com/dont-worry.html" # note that the starting address is the address of the first article, through the page of this article # You can use the BeautifulSoup module to obtain the address file = open (r "E: \ 123.txt"," a ") def pageloop (url) of the previous article ): page = urllib2.urlopen (url) soup = BeautifulSoup (page) img = soup. findAll (['img ']) if img = []: print "no image on the current page" return else: for myimg I N 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.urlopen (url) soup = BeautifulSoup (page) for spanclass in soup. findAll (attrs = {"class": "article-nav-prev"}): # print spanclass if spanclass. find ('Article-nav-prev' )! =-1: pattern = re. compile (r 'HTTP: // www.bkjia.com/?s=html') pageurl = pattern. findall (str (spanclass) for I in pageurl: # print I getthenextpage (I) getthenextpage (baseurl) print "the end! "File. close ()

Finally, let me talk to my colleagues who have just started website preparation. It is best to name images in the form of numbers, English letters, and pinyin. Otherwise, it will be difficult to modify the image, therefore, it is better to develop a good habit from the very beginning and use the correct naming rules to name articles and images.




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.