1、mysql数据库用于存储大量数据。

2、Navicat for MySQL以图形和表格等形式管理数据库工具。

3、编程语言python3与环境配置

4、pythcharm集成开发环境(社区版)不需要激活

5、Python包管理器Anaconda3(爬虫主要用到两个包requests,pymysql)与环境配置(网上可找安装教程).

链接:https://pan.baidu.com/s/1Zef6oPmtNZ4sWBXyAMBSgA
提取码:am9q

应用:

1、正则表达式提取猫眼top100电影中的电影名称、主演和上映时间

import pymysql
import requests
import re def get_text(url):
r = requests.get(url)
r.raise_for_status()
r.encoding = r.apparent_encoding
return r.text def parse_html(url, list):
demo = get_text(url)
patern = re.compile('class="name".*?title="(.*?)".*?:(.*?)\s*?</p>.*?:(\d{4}-\d{2}-\d{2})', re.S)
results = re.findall(patern, demo)
for result in results:
list.append(result)
return list list = []
for i in range(0,10):
url = 'https://maoyan.com/board/4?offset='+str(10*i)
list = parse_html(url, list) count = 0
for i in list:
count = count + 1
print(i)
print("一共有"+str(count)+"条数据!")

2、正则表达式提取西北大学讲座信息

import requests
import pymysql
import re
import os def get_text(url):
r = requests.get(url)
r.raise_for_status()
r.encoding = r.apparent_encoding
return r.text def parse_html(url, list):
demo = get_text(url)
patern = re.compile('<li><span class="fr">\[(.*?)\].*?&nbsp;&nbsp;(.*?)</a>',re.S)
results = re.findall(patern, demo)
for result in results:
list.append(result)
return list list = []
url = 'http://computer.swu.edu.cn/s/computer/kxyj2xsky/index.html'
list = parse_html(url,list)
for i in range(2, 5):
url = "http://computer.swu.edu.cn/s/computer/kxyj2xsky/index_"+str(i)+".html"
list = parse_html(url, list) count = 0
for i in list:
count = count + 1
print(i)
print("一共有"+str(count)+"条数据!")

3、爬取图片

import requests
import pymysql
import re
import os def get_text(url):
r = requests.get(url)
r.raise_for_status()
r.encoding = r.apparent_encoding
return r.text def parse_html(url, list):
demo = get_text(url)
patern = re.compile('<li><span class="fr">\[(.*?)\].*?&nbsp;&nbsp;(.*?)</a>',re.S)
results = re.findall(patern, demo)
for result in results:
list.append(result)
return list list = []
url = 'http://computer.swu.edu.cn/s/computer/kxyj2xsky/index.html'
list = parse_html(url,list)
for i in range(2, 5):
url = "http://computer.swu.edu.cn/s/computer/kxyj2xsky/index_"+str(i)+".html"
list = parse_html(url, list) count = 0
for i in list:
count = count + 1
print(i)
print("一共有"+str(count)+"条数据!")
import pymysql
import requests
from hashlib import md5
import re
import os # db = pymysql.connect('localhost', 'root', '1458555801', 'world')
# print("数据库连接成功!")
# print("---------------------------------------------------")
# r = requests.get("https://python123.io/ws/demo.html")
# print(r.text) # r = requests.get("https://python123.io/ws/demo.html")
# print(r)
# # 提取网页文本内容
# print(r.text)
# # 提取网页编码方式
# print(r.encoding)
# print(r.apparent_encoding)
# r.encoding = r.apparent_encoding
# # 打印状态码
# print(r.status_code)
# # 捕获异常
# print(r.raise_for_status()) def get_text(url):
r = requests.get(url)
r.raise_for_status()
r.encoding = r.apparent_encoding
return r.text # print(get_text('https://python123.io/ws/demo.html')) # demo = get_text('https://python123.io/ws/demo.html')
# result = re.search('Th.*?ge', demo)
# print(result)
# print(result.group())
# result2 = re.search('http.*?001', demo)
# print(result2.group())
# result3 = re.findall('<p.*?</p>', demo, re.S)
# print(result3) def parse_html(url, list):
demo = get_text(url)
# 将正则表达式编译成正则表达式对象,方便复用该正则表达式
# ".*?" :匹配任意字符串
# [\u4e00-\u9fa5] :匹配中文
# (\d{4}-\d{2}-\d{2}) : 匹配日期
patern = re.compile('<li><span\sclass="fr">\[(\d{4}-\d{2}-\d{2})\].*?&nbsp;&nbsp;(.*?)</a></li>', re.S)
results = re.findall(patern, demo)
for result in results:
list.append(result)
return list list = []
url = 'http://computer.swu.edu.cn/s/computer/kxyj2xsky/index.html'
list = parse_html(url, list)
for i in range(2,5):
# http://computer.swu.edu.cn/s/computer/kxyj2xsky/index_2.html
url = 'http://computer.swu.edu.cn/s/computer/kxyj2xsky/index_'+str(i) + '.html'
list = parse_html(url, list) count = 0
for i in list:
count = count + 1
print(i)
print("一共有"+str(count)+"条数据!") # def download_image(url):
# r = requests.get(url)
# r.raise_for_status()
# save_image(r.content)
#
# def save_image(content):
# file_path = '{0}/{1}.{2}'.format('C:/Users/Think/Desktop/image', md5(content).hexdigest(), 'jpg')
# if not os.path.exists(file_path):
# with open(file_path, 'wb') as f:
# f.write(content)
# f.close() # for i in list:
# download_image(i)
# print("下载成功")

python爬虫相关安装与应用的更多相关文章

  1. Mac os 下 python爬虫相关的库和软件的安装

      由于最近正在放暑假,所以就自己开始学习python中有关爬虫的技术,因为发现其中需要安装许多库与软件所以就在这里记录一下以避免大家在安装时遇到一些不必要的坑. 一. 相关软件的安装:   1. h ...

  2. Python爬虫笔记安装篇

    目录 爬虫三步 请求库 Requests:阻塞式请求库 Requests是什么 Requests安装 selenium:浏览器自动化测试 selenium安装 PhantomJS:隐藏浏览器窗口 Ph ...

  3. python 爬虫库安装

    一键安装python爬虫库 pip3 install requests selenium beautifulsoup4 pyquery pymysql pymongo redis flask djan ...

  4. python爬虫相关

    一.Python re模块的基本用法: https://blog.csdn.net/chenmozhe22/article/details/80601971 二.爬取网页图片 https://www. ...

  5. python爬虫相关基础概念

    什么是爬虫 爬虫就是通过编写程序模拟浏览器上网,然后让其去互联网上抓取数据的过程. 哪些语言可以实现爬虫 1.php:可以实现爬虫.但是php在实现爬虫中支持多线程和多进程方面做得不好. 2.java ...

  6. 【Python爬虫】安装 pyQuery 遇到的坑 Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?

    windows 64位操作系统下,用 Python 抓取网页,并用 pyQuery 解析网页 pyQuery是jQuery在python中的实现,能够以jQuery的语法来操作解析HTML文档,十分方 ...

  7. python 爬虫相关含Scrapy框架

    1.从酷狗网站爬取 新歌首发的新歌名字.播放时长.链接等 from bs4 import BeautifulSoup as BS import requests import re import js ...

  8. 吴裕雄--天生自然PYTHON爬虫:安装配置MongoDBy和爬取天气数据并清洗保存到MongoDB中

    1.下载MongoDB 官网下载:https://www.mongodb.com/download-center#community 上面这张图选择第二个按钮 上面这张图直接Next 把bin路径添加 ...

  9. python爬虫-MongoDB安装配置

    MongoDB安装配置: 在安装配置MongoDB的过程中遇到了很多问题,现在重新梳理一遍安装流程.遇到的问题及其解决方法 系统版本:Windows 10 MongoDB版本:4.2.1 1.下载地址 ...

随机推荐

  1. 做股票软件用的各种k线图

    这是各种k线图地址: http://echarts.baidu.com/echarts2/doc/example.html 个人公众号谢谢各位老铁支持 本人qq群也有许多的技术文档,希望可以为你提供一 ...

  2. 【vue-cli 3.0】 vue.config.js配置 - 路径别名

    如何配置vue-cli 3中vue.config.js的路径别名? 前段时间更新电脑重装了一下vue-cli,发现了vue-cli已经更新到3.0版.用来搭建项目后发现简化了很多,而且配置文件现在可以 ...

  3. 细数不懂Spring底层原理带来的伤与痛

    原文链接:https://www.jianshu.com/p/c9de414221ac?utm_campaign=haruki&utm_content=note&utm_medium= ...

  4. 1.使用kubeadm安装kubernetes

    一.环境准备 所有规划主机(一台master,两台node)均需操作 1.关闭防火墙,selinux [root@node1 ~]# systemctl stop firewalld [root@no ...

  5. 并行操作多个序列map

    >>> def add1(a): return a + 1 >>> def add2(a,b): return a + b >>> def add ...

  6. 【GDOI2014模拟】服务器

    前言 直到比赛最后几分钟,才发现60%数据居然是一个水dp,结果没打完. 题目 我们需要将一个文件复制到n个服务器上,这些服务器的编号为S1, S2, -, Sn. 首先,我们可以选择一些服务器,直接 ...

  7. 【Heaven Cow与God Bull】题解

    题目 Description __int64 ago,there's a heaven cow called sjy... A god bull named wzc fell in love with ...

  8. 链接收藏:bullet物理引擎不完全指南

    这个也是博客园的文章,编辑得也很好,就不copy了,结尾还有PDF: https://www.cnblogs.com/skyofbitbit/p/4128347.html 完结

  9. 【bzoj3162】独钓寒江雪

    *题目描述: *题解: 树哈希+组合数学.对于树的形态相同的子树就一起考虑. *代码: #include <cstdio> #include <cstring> #includ ...

  10. 普通用户sudo权限

    需求: 1>创建一个saipu普通用户,不允许使用 rm 和 passwd root 和 sudo su - root 命令,其他命令均允许且 sudo 时不用输入密码 2>创建一个lwd ...