


Recommended Zhonggu Education Python videos (courseware, source code)
《中谷教育Python视频教程》讲的是Python开发的入门教程,它将介绍Python语言的特点和适用范围,Python基本的数据类型,条件判断和循环,函数,以及Python特有的切片和列表生成式。希望本python教程能够让您快速入门并编写简单的Python程序。
课程播放地址:http://www.php.cn/course/501.html
该老师讲课风格:
教师讲课生动形象,机智诙谐,妙语连珠,动人心弦。一个生动形象的比喻,犹如画龙点睛,给学生开启智慧之门;一种恰如其分的幽默,引来学生会心的微笑,如饮一杯甘醇的美酒,给人以回味和留恋;哲人的警句、文化的箴言不时穿插于讲述中间,给人以思考和警醒。
本视频中较为难点是爬虫了:
1、单个网页的简易爬虫
以下爬虫的主要功能是爬取百度贴吧中某一页面的所有图片。代码由主要有两个函数:其中getHtml()通过页面url获取其对应的html内容,getImage()则通过解析html获取图片地址,实现图片的下载。
代码如下:
import urllib import re def getHtml(url): """通过页面url获取其对应的html内容 """ page = urllib.urlopen(url) #打开页面 content = page.read() #读取页面内容 return content def getImage(html): """通过解析html获取图片地址,实现图片的下载 """ regx =r'src="(.+?\.jpg)" pic_ext' #利用正则表达式获得图片url imgreg = re.compile(regx) imglist = re.findall(imgreg,html) x = 0 for imgurl in imglist: filepath ='F:\\Downloads\\'+str(x)+'.jpg' urllib.urlretrieve(imgurl,filepath) #将图片下载到本地 x += 1 print 'completed!' html = getHtml('http://tieba.baidu.com/p/2505265675') imglist = getImage(html)
2、爬取多网页的框架
这里只讲基本思想:第一步是选择一个起始页面,可以直接选择某个网站的主页作为起始页面;第二步是分析这个起始页面的所有链接,然后爬取所有链接的内容;第三步就是无休无止的递归过程,分析爬虫所及的所有子页面内部链接,如果没有爬取过,则继续无休无止的爬取。
借用知乎上谢科兄弟的一段代码来说明。设定初始页面initial_page,爬虫就从这里开始获取页面,url_queue用来存将要爬取的页面队列,seen用来存爬取过的页面。
import Queue initial_page ="http://www.renminribao.com" url_queue =Queue.Queue() seen = set() seen.insert(initial_page) url_queue.put(initial_page) while True: if url_queue.size()>0: current_url = url_queue.get() #取出队例中第一个的url store(current_url) #把这个url代表的网页存储好 for next_url inextract_urls(current_url): #提取把这个url里链向的url if next_url not in seen: seen.put(next_url) url_queue.put(next_url) else: break
这里还给大家推荐了源码资源的下载:http://www.php.cn/xiazai/learn/1944
这个给大家分享了视频的课件
The above is the detailed content of Recommended Zhonggu Education Python videos (courseware, source code). For more information, please follow other related articles on the PHP Chinese website!

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

VS Code can be used to write Python and provides many features that make it an ideal tool for developing Python applications. It allows users to: install Python extensions to get functions such as code completion, syntax highlighting, and debugging. Use the debugger to track code step by step, find and fix errors. Integrate Git for version control. Use code formatting tools to maintain code consistency. Use the Linting tool to spot potential problems ahead of time.

VS Code extensions pose malicious risks, such as hiding malicious code, exploiting vulnerabilities, and masturbating as legitimate extensions. Methods to identify malicious extensions include: checking publishers, reading comments, checking code, and installing with caution. Security measures also include: security awareness, good habits, regular updates and antivirus software.

Running Python code in Notepad requires the Python executable and NppExec plug-in to be installed. After installing Python and adding PATH to it, configure the command "python" and the parameter "{CURRENT_DIRECTORY}{FILE_NAME}" in the NppExec plug-in to run Python code in Notepad through the shortcut key "F6".
