这是一个简单的Python脚本,主要从懒人图库下载JavaScript特效模板,在脚本中使用了gevent这个第三方库,使用的时候需要先安装。
#!/usr/bin/python # -*- coding: utf-8 -*- import urllib,os,sys import gevent,re from gevent import monkey from bs4 import BeautifulSoup gevent.monkey.patch_socket() ''' Description:Python 爬虫抓取懒人图库的JS脚本模板 Author:admin Create-Date:2015-05-25 Version:1.0 ''' HTTP_URL = 'http://www.lanrentuku.com%s' DOWNLOAD_URL = HTTP_URL[:-2] + '/js/d%szip' reg=r'\d{1,}\.+' def encode(text): return text.encode("utf8") def createDirectory(curPath): myPath = os.path.join(getSubDirectory(), u'JS代码模板') if not os.path.exists(myPath): os.mkdir(myPath) return os.path.join(myPath, curPath) def getSubDirectory(): return os.getcwd() def schedule(a, b, c): per = 100.0 * a * b / c if per > 100 : per = 100 sys.stdout.write('%.1f%%\r' % per) sys.stdout.flush() def geturllist(url): url_list = {} html = urllib.urlopen(url) content = html.read() html.close() # 用BeautifulSoup解析 decodeHtml = BeautifulSoup(content) try: aTags = decodeHtml.find_all('div', {'class':'list-pngjs'})[0].find_all('a') except IndexError, e: print e aTags = None # 获取链接地址和标题 if aTags is not None: for a_tag in aTags: url_list[HTTP_URL % a_tag.get('href')] = a_tag.get_text() return url_list def download(down_url): try: m=re.search(reg,down_url[0]) name = DOWNLOAD_URL % m.group(0) urllib.urlretrieve(name,createDirectory(down_url[1] + name[-4:]),schedule) except Exception, e: print e.message def getpageurl(xUrl): # 进行列表页循环 return [xUrl % page for page in xrange(1,49)] if __name__ == '__main__': jobs = [] pageurl = getpageurl('http://www.lanrentuku.com/js/p%s.html') # 爬取所有链接 for i in pageurl: for k in geturllist(i).items(): jobs.append(gevent.spawn(download, k)) gevent.joinall(jobs)
以上所述就是本文的全部内容了,希望大家能够喜欢。

To maximize the efficiency of learning Python in a limited time, you can use Python's datetime, time, and schedule modules. 1. The datetime module is used to record and plan learning time. 2. The time module helps to set study and rest time. 3. The schedule module automatically arranges weekly learning tasks.

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.

Python is suitable for data science, web development and automation tasks, while C is suitable for system programming, game development and embedded systems. Python is known for its simplicity and powerful ecosystem, while C is known for its high performance and underlying control capabilities.

You can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.

Python is widely used in the fields of web development, data science, machine learning, automation and scripting. 1) In web development, Django and Flask frameworks simplify the development process. 2) In the fields of data science and machine learning, NumPy, Pandas, Scikit-learn and TensorFlow libraries provide strong support. 3) In terms of automation and scripting, Python is suitable for tasks such as automated testing and system management.

You can learn the basics of Python within two hours. 1. Learn variables and data types, 2. Master control structures such as if statements and loops, 3. Understand the definition and use of functions. These will help you start writing simple Python programs.

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version
SublimeText3 Linux latest version

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software