0
点赞
收藏
分享

微信扫一扫

Python 爬虫学习 系列教程

 

 

Python爬虫 --- 中高级爬虫学习路线

图时,可以把图片保存到本地在打开查看。。。

Python 爬虫学习 系列教程_python

 

 

Python爬虫学习系列教程

 

From:​​https://cuiqingcai.com/1052.html​​

 

一、爬虫入门

 

1. ​​Python爬虫入门一之综述​​

2. ​​Python爬虫入门二之爬虫基础了解​​

3. ​​Python爬虫入门三之Urllib库的基本使用​​

4. ​​Python爬虫入门四之Urllib库的高级用法​​

5. ​​Python爬虫入门五之URLError异常处理​​

6. ​​Python爬虫入门六之Cookie的使用​​

7. ​​Python爬虫入门七之正则表达式​​

 

 

二、爬虫实战

 

1. ​​Python爬虫实战一之爬取糗事百科段子​​

# -*- coding:utf-8 -*-

import requests
import re
import os


class QSBK(object):
def __init__(self):
self.__url = r'https://www.qiushibaike.com'
self.__head = None
self.__data = None
self.__proxy = None

def drop_n(self, content):
'''
去掉换行符 和 网页注释
:param content: html 网页内容
:return: 返回去掉换行符之后的网页内容
'''
content = re.sub(r'\n', '', content)
content = re.sub(r'<!--.*?-->', '', content)
return content

def crawl(self):
r = requests.get("{0}/hot".format(self.__url))
if r.status_code == 200:
print("status_code : {0}".format(r.status_code))
print r.url
content = self.drop_n(r.content)
page_num_regex = re.compile(r'<li><span class="current" >(.*?)</span></li>')
page_num = re.findall(page_num_regex, content)[0]
s = r'<div class="article block untagged mb15.*?>' \
r'<div class="author clearfix">' \
r'<a .*?>.*?</a><a.*?web-list-author-text.*?><h2>(.*?)</h2></a>' \
r'.*?<a href="(.*?)".*?web-list-content.*?><div class="content"><span>(.*?)</span>'
# print s
pattern = re.compile(s)
items = re.findall(pattern, content)
print u'第 {0} 页'.format(page_num)
for item in items:
print item[0], item[1], item[2]
#os.system('pause')
raw_input(u'按 Enter键 继续...')
next_page_regex = re.compile(r'<ul class="pagination">.*<li><a href="(.*?)".*?><span.*?/span></a></li></ul>')
next_page = re.findall(next_page_regex, content)[0]
while next_page:
next_url = '{0}{1}'.format(self.__url, next_page)
r = requests.get(next_url)
if r.status_code == 200:
print("status_code : {0}".format(r.status_code))


print r.url
content = self.drop_n(r.content)
page_num = re.findall(page_num_regex, content)[0]
items = re.findall(pattern, content)
print u'第 {0} 页'.format(page_num)
for item in items:
print item[0], item[1], item[2]
# os.system('pause')
raw_input(u'按 Enter键 继续...')
next_page = re.findall(next_page_regex, content)[0]
print next_page
pass

else:
print("status_code : {0}".format(r.status_code))
pass


if __name__ == "__main__":
qsbk = QSBK()
qsbk.crawl()
pass

运行结果截图:

Python 爬虫学习 系列教程_python_02

 

2. ​​Python爬虫实战二之爬取百度贴吧帖子​​

3. ​​Python爬虫实战三之实现山东大学无线网络掉线自动重连​​

4. ​​Python爬虫实战四之抓取淘宝MM照片​​

5. ​​Python爬虫实战五之模拟登录淘宝并获取所有订单​​

6. ​​Python爬虫实战六之抓取爱问知识人问题并保存至数据库​​

7. ​​Python爬虫实战七之计算大学本学期绩点​​

8. ​​Python爬虫实战八之利用Selenium抓取淘宝匿名旺旺​​

 

 

三、爬虫利器

 

1. ​​Python爬虫利器一之Requests库的用法​​

2. ​​Python爬虫利器二之Beautiful Soup的用法​​

3. ​​Python爬虫利器三之Xpath语法与lxml库的用法​​

4. ​​Python爬虫利器四之PhantomJS的用法​​

5. ​​Python爬虫利器五之Selenium的用法​​

6. ​​Python爬虫利器六之PyQuery的用法​​

 

 

四、爬虫进阶

 

1. ​​Python爬虫进阶一之爬虫框架概述​​

2. ​​Python爬虫进阶二之PySpider框架安装配置​​

3. ​​Python爬虫进阶三之爬虫框架Scrapy安装配置​​

4. ​​Python爬虫进阶四之PySpider的用法​​

5. ​​Python爬虫进阶五之多线程的用法​​

6. ​​Python爬虫进阶六之多进程的用法​​

7. ​​Python爬虫进阶七之设置ADSL拨号服务器代理​​

 

​​《一只小爬虫》​​

​​《一只并发的小爬虫》​​

​​《Python与简单网络爬虫的编写》​​

​​《Python写爬虫——抓取网页并解析HTML》​​

​​《​​​​[Python]网络爬虫(一):抓取网页的含义和URL基本构成​​》

​​《​​​​[Python]网络爬虫(二):利用urllib2通过指定的URL抓取网页内容​​》

​​《​​​​[Python]网络爬虫(三):异常的处理和HTTP状态码的分类​​》

​​《​​​​[Python]网络爬虫(四):Opener与Handler的介绍和实例应用​​》

​​《​​​​[Python]网络爬虫(五):urllib2的使用细节与抓站技巧​​》

​​《[Python]网络爬虫(六):一个简单的百度贴吧的小爬虫》​​

​​《[Python]网络爬虫(七):Python中的正则表达式教程》​​

​​《[Python]网络爬虫(八):糗事百科的网络爬虫(v0.2)源码及解析》​​

​​《[Python]网络爬虫(九):百度贴吧的网络爬虫(v0.4)源码及解析》​​

​​《[Python]网络爬虫(十):一个爬虫的诞生全过程(以山东大学绩点运算为例)》​​

​​《​​​​用python爬虫抓站的一些技巧总结 zz​​》

​​《python爬虫高级代码》​​

 

 

 

 

 



举报

相关推荐

0 条评论