哎,以前写博文的时候没注意,有些图片用QQ来截取,获得的图片文件名都是类似于QQ截图20120926174732-300×15.png的形式,昨天用ftp备份网站文件的时候发现,中文名在flashfxp里面显示的是乱码的,看起来好难受,所以写了一个python小脚本,爬取整个网站,然后获取每个文章页面的图片名,并判断如果是类似于QQ截图20120926174732-300×15.png的形式就输出并将该图片地址和对应的文章地址保存在文件中,然后通过该文件来逐个修改。
好了,下面是程序代码:
import urllib2 from bs4 import BeautifulSoup import re import sys reload(sys) sys.setdefaultencoding('utf-8') baseurl = "http://www.jb51.net/dont-worry.html" #说明下,起始地址是第一篇文章的地址,通过该文章的页面就 #可以使用BeautifulSoup模块来获取上一篇文章的地址 file = open(r"E:\123.txt","a") def pageloop(url): page = urllib2.urlopen(url) soup = BeautifulSoup(page) img = soup.findAll(['img']) if img == []: print "当前页面没有图片" 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.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.jb51.net/\S*html') pageurl = pattern.findall(str(spanclass)) for i in pageurl: #print i getthenextpage(i) getthenextpage(baseurl) print "the end!" file.close()
最后,对和我以前刚开始做网站的同学说下,图片命名的话最好是用数字形式或者是英文、拼音的形式,要不然到最后想修改的话就麻烦了,所以最好就是从刚开始就养成好的习惯,用正确的命名规范来问文章、图片来命名,这样就会好很多。

The article discusses Python's new "match" statement introduced in version 3.10, which serves as an equivalent to switch statements in other languages. It enhances code readability and offers performance benefits over traditional if-elif-el

Exception Groups in Python 3.11 allow handling multiple exceptions simultaneously, improving error management in concurrent scenarios and complex operations.

Function annotations in Python add metadata to functions for type checking, documentation, and IDE support. They enhance code readability, maintenance, and are crucial in API development, data science, and library creation.

The article discusses unit tests in Python, their benefits, and how to write them effectively. It highlights tools like unittest and pytest for testing.

Article discusses access specifiers in Python, which use naming conventions to indicate visibility of class members, rather than strict enforcement.

Article discusses Python's \_\_init\_\_() method and self's role in initializing object attributes. Other class methods and inheritance's impact on \_\_init\_\_() are also covered.

The article discusses the differences between @classmethod, @staticmethod, and instance methods in Python, detailing their properties, use cases, and benefits. It explains how to choose the right method type based on the required functionality and da

InPython,youappendelementstoalistusingtheappend()method.1)Useappend()forsingleelements:my_list.append(4).2)Useextend()or =formultipleelements:my_list.extend(another_list)ormy_list =[4,5,6].3)Useinsert()forspecificpositions:my_list.insert(1,5).Beaware


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6
Visual web development tools

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools
