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.