python爬虫相关安装与应用
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">\[(.*?)\].*? (.*?)</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">\[(.*?)\].*? (.*?)</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})\].*? (.*?)</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爬虫相关安装与应用的更多相关文章
- Mac os 下 python爬虫相关的库和软件的安装
由于最近正在放暑假,所以就自己开始学习python中有关爬虫的技术,因为发现其中需要安装许多库与软件所以就在这里记录一下以避免大家在安装时遇到一些不必要的坑. 一. 相关软件的安装: 1. h ...
- Python爬虫笔记安装篇
目录 爬虫三步 请求库 Requests:阻塞式请求库 Requests是什么 Requests安装 selenium:浏览器自动化测试 selenium安装 PhantomJS:隐藏浏览器窗口 Ph ...
- python 爬虫库安装
一键安装python爬虫库 pip3 install requests selenium beautifulsoup4 pyquery pymysql pymongo redis flask djan ...
- python爬虫相关
一.Python re模块的基本用法: https://blog.csdn.net/chenmozhe22/article/details/80601971 二.爬取网页图片 https://www. ...
- python爬虫相关基础概念
什么是爬虫 爬虫就是通过编写程序模拟浏览器上网,然后让其去互联网上抓取数据的过程. 哪些语言可以实现爬虫 1.php:可以实现爬虫.但是php在实现爬虫中支持多线程和多进程方面做得不好. 2.java ...
- 【Python爬虫】安装 pyQuery 遇到的坑 Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
windows 64位操作系统下,用 Python 抓取网页,并用 pyQuery 解析网页 pyQuery是jQuery在python中的实现,能够以jQuery的语法来操作解析HTML文档,十分方 ...
- python 爬虫相关含Scrapy框架
1.从酷狗网站爬取 新歌首发的新歌名字.播放时长.链接等 from bs4 import BeautifulSoup as BS import requests import re import js ...
- 吴裕雄--天生自然PYTHON爬虫:安装配置MongoDBy和爬取天气数据并清洗保存到MongoDB中
1.下载MongoDB 官网下载:https://www.mongodb.com/download-center#community 上面这张图选择第二个按钮 上面这张图直接Next 把bin路径添加 ...
- python爬虫-MongoDB安装配置
MongoDB安装配置: 在安装配置MongoDB的过程中遇到了很多问题,现在重新梳理一遍安装流程.遇到的问题及其解决方法 系统版本:Windows 10 MongoDB版本:4.2.1 1.下载地址 ...
随机推荐
- cocos随笔
随笔: [ 1 ] active能隐藏元素,且不占空间,但仍存在,索引时,仍能得到 [ 2 ] 碰到参数传不进去的时候可以试着用属性赋值的方法代替传参 [ 3 ] getChildByName是按照 ...
- DevExpress v19.1新版亮点——WinForms篇(一)
行业领先的.NET界面控件DevExpress v19.1终于正式发布,本站将以连载的形式介绍各版本新增内容.在本系列文章中将为大家介绍DevExpress WinForms v19.1中新增的一些控 ...
- Python---进阶---文件操作---搜索文件和保存搜索结果
### 编写一个程序,用户输入文件名以及开始搜索的路径,搜索该文件是否存在,如果遇到文件夹,则进入该文件夹继续搜索 - input 去接受用户输入的文件名和开始搜索的路径 - os.path.isdi ...
- Oracle RAC业务bug导致部分数据丢失处理
问题描述:业务部门在10月26日发现某张基础表中丢失部分数据,系为9月份录入系统的基础数据丢失 Oracle RAC环境做的RMAN备份,10月18日做过expdp数据泵备份,丢失数据表名为T_GL_ ...
- Gparted for partition of Linux on graphic interface
You can change the partition table on Linux by a group of tools, which is tool comprehansive for a n ...
- 错误: 找不到或无法加载主类 org.sang.BlogserverApplication
错误: 找不到或无法加载主类 org.sang.BlogserverApplication
- Eclipse 中的 parameter参数,property属性,preference首选项 区别
parameter参数 1.配置框架 web.xml <init-param> <param-name>contextConfigLocation</param-name ...
- CF1012F Passports
http://codeforces.com/problemset/problem/1012/F 题解 考虑\(p=1\)的情况. 我们可以把题意理解成平面上有一些线段,你需要给每条线段分配一个长度给定 ...
- 如何将一个SpringBoot简便地打成一个war包(亲测有效)
正常情况下SpringBoot项目是以jar包的形式,通过命令行: 来运行的,并且SpringBoot是内嵌Tomcat服务器,所以每次重新启动都是用的新的Tomcat服务器.正因如此,也出现了一个问 ...
- 职位-CEO:CEO
ylbtech-职位-CEO:CEO 首席执行官(Chief Executive Officer,缩写CEO),职位名称,是在一个企业中负责日常事务的最高行政官员,主司企业行政事务,又称作司政.行政总 ...