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.下载地址 ...
随机推荐
- bzoj3091 城市旅行 LCT + 区间合并
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=3091 题解 调了整个晚自习才调出来的问题. 乍一看是个 LCT 板子题. 再看一眼还是个 LC ...
- tarjan相关模板
感性理解: o(* ̄︶ ̄*)o ^_^ \(^o^)/~ 1. 当根节点有大于两个儿子时,割掉它,剩下的点必然不联通(有两个强连通分量),则他为割点. 那么对于非根节点,在无向图G中,刚且仅当点u存 ...
- 校赛 你的粪坑V2
原题 今天举办程序设计比赛,2点30分开始,然而你睡到了2点25分,紧张的你将头发梳成大人模样,敷上一层最贵的面膜,穿着滑板鞋,以飞一般的速度奔向计算机学院准备参加程序设计竞赛!冠军是你的! 然而路上 ...
- UOJ428. 【集训队作业2018】普通的计数题
http://uoj.ac/problem/428 题解 神仙题. 考虑最后一定是放了一个\(1\),然后把其他位置都删掉了. 再考虑到对于序列中的每个位置都对应了一次操作. 我们可以对于每个放\(1 ...
- 运行job检验单元测试覆盖率
http://ns.jenkins.baidu.com/user/anyixing/my-views/view/Map_ut/job/poi-zhunru/ 1在http://ns.jenkins.b ...
- 微信小程序 checkbox 组件
checkbox 组件 是一个多选框组件,还可以使用 checkbox-group 组件 来进行绑定事件和实现,真正意义上的多选 checkbox的属性: value: 属性值 字符串 当在 chec ...
- percona-toolkit 工具介绍
percona-toolkit 工具介绍 percona-toolkit 是一组高级命令行工具的集合,用来执行各种通过手工执行非常复杂和麻烦的mysql和系统任务.这些任务包括: 检查master和s ...
- /etc/init.d# ./redis-server start
root@ubuntu:/etc/init.d# ll total drwxr-xr-x root root May : ./ drwxr-xr-x root root May : ../ -rwxr ...
- 小程序mpvue中动态切换echarts图表
如果你用mpvue,而且还想用echarts,那么这个包你可以以来一下 https://github.com/F-loat/mpvue-echarts 考虑到多个页面都休要用,所以抽出来作为一个组件, ...
- sc 使用了配置中心后,如何设置远程和本地配置的优先级
在 spring 中,如何获取一个 key 的值? applicationContext.getEnvironment().getProperty("swagger.show") ...