![](https://img-blog.csdnimg.cn/20190918135101160.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
python爬虫
使用PY语言进行爬虫
CY3761
这个作者很懒,什么都没留下…
展开
-
PY爬虫 | 爬取下厨房的本周最受欢迎
# CY3761 | 2021-10-27 20:03# 爬取下厨房的本周最受欢迎-列表数据import base64import os.pathfrom urllib import request # 下载图片import openpyxlfrom openpyxl.worksheet.hyperlink import Hyperlink # 插入链接from openpyxl.drawing.image import Image # 插入图片from pyquery impor原创 2022-01-10 17:18:31 · 465 阅读 · 0 评论 -
爬虫 | CSDN专栏目录
from requests_plus import getfrom requests_plus import pq, getPquid = '014534808'# cid = '10711684' # Python从入门到精通cid = '11432885' # 爬虫url = f'https://blog.csdn.net/u{uid}/category_{cid}.html'r, t, items = getPq(url, { 'person': ['.column_pers原创 2021-12-25 22:57:03 · 91 阅读 · 0 评论 -
爬虫 | tqdm 下载进度效果
# CY3761 | 2021-12-23 22:39import os.pathimport timefrom fake_useragent import UserAgentfrom requests import getfrom tqdm import tqdm# https://pypi.org/project/tqdm/# 下载文件地址 保存文件地址 不存入默认当前目录下的下载文件名def download(u, filename=None, isRemove=False):原创 2021-12-24 21:42:10 · 569 阅读 · 0 评论 -
爬虫 | urllib.parse
# CY3761 | 2021-12-23 11:50import os.pathimport typesfrom urllib import parseupDict = parse.__dict__upDictKeys = upDict.keys()"""print('-' * 80)print('parse.__dict__(keys)')[print(str(k).zfill(2), _) for k, _ in enumerate(upDictKeys) if not _.st原创 2021-12-23 17:34:55 · 496 阅读 · 0 评论 -
爬虫 | 爬取百度贴吧 (仅学习用)
# CY3761 | 2021-12-19 12:10import randomimport timefrom fake_useragent import UserAgentfrom requests import getfrom pyquery import PyQuery as pqimport hashlibimport os# print(os.getcwd()) # 当前执行文件的目录# 爬取百度贴吧# 一般只能爬取一页, 第二页会触发 (百度安全验证)clas原创 2021-12-19 19:34:44 · 520 阅读 · 0 评论 -
爬虫 | 王者荣耀高清壁纸-多线程
# CY3761 | 2021-11-04 18:23import jsonimport osimport queueimport timeimport urllibimport requestsfrom urllib import parseimport threadingfrom queue import Queue# 王者荣耀-官网 https://pvp.qq.com# 王者荣耀-高清壁纸 https://pvp.qq.com/web201605/wallpaper.s原创 2021-12-16 11:49:33 · 580 阅读 · 0 评论 -
爬虫 | 王者荣耀高清壁纸-单线程
# CY3761 | 2021-11-04 11:45# 把请求事务等封装成函数 一步步进行import jsonimport osimport timeimport urllib.parseimport requests# 创建文件夹# -------------------------------------------------------------dirPath = '10.王者荣耀/'jsonDirPath = dirPath + 'json/'imgDirPath原创 2021-12-16 11:45:23 · 280 阅读 · 0 评论 -
了解Requests库的使用
包含get、from-post、json-post,upload–post# CY3761 | 2021-12-14 10:14# 全方面的掌握Requests库的使用【python爬虫入门进阶】(02)# https://feige.blog.csdn.net/article/details/120935824import requestsfrom fake_useragent import UserAgentimport osheaders = { 'User-Agent':原创 2021-12-14 11:29:51 · 708 阅读 · 0 评论 -
小玩意-HTML实体字符转换
# CY3761 | 2021-12-08 17:57# 在HTML实体字符中, 最常用就是 这是表示一个空格# 如何实现把 实体字符进行转换成正常的汉字呢?# https://www.toolnb.com/Tools/Api/htmlende.html"""data: 中文type: encode"""# https://www.toolnb.com/Tools/Api/htmlende.html"""data: 中文原创 2021-12-09 12:04:47 · 505 阅读 · 0 评论 -
requests的 post 与 session.post 加 代理补充
# requests的 post 与 session.post# 案例: 访问 https://www.xbiquge.la/modules/article/bookcase.php (新笔趣阁-我的书架)# 此网址在未登录时候不能访问import requestsfrom fake_useragent import UserAgentfrom pyquery import PyQuery as pqdef resPrint(res): print('-' * 80) pri原创 2021-11-27 19:54:22 · 1025 阅读 · 0 评论 -
requests.get
# requests 第三方请求库# 安装: pip install requests# 测试: requests -v# 比较常用的方法# requests.get()# requests.post()# requests.session()# 返回属性# resp.status_code 状态码# resp.content 二进制数据 图片等资源# resp.text 字符串数据# resp.encoding 编码(可用于设置返回的text编码)# resp.url 请求地址原创 2021-11-27 15:34:15 · 1773 阅读 · 0 评论 -
utllib-cookie + utllib-error
utllib-cookiefrom os.path import existsfrom os import makedirsfrom fake_useragent import UserAgentfrom urllib import requestfrom urllib import parsefrom http import cookiejarfrom hashlib import md5class UrllibCookie(): def __init__(self, save原创 2021-11-27 10:53:58 · 1240 阅读 · 0 评论 -
utllib.request
from urllib.parse import urlencodefrom urllib import requestfrom pyquery import PyQuery as pqfrom fake_useragent import UserAgentdef requestPlus(**kwargs): url = kwargs.get('url') if not url: raise Exception('请求地址为空') i原创 2021-11-26 21:04:18 · 838 阅读 · 0 评论 -
urllib.parse
# CY3761 | 2021-11-20 17:15from urllib import parse# 设置一个字典query = { 'kw': '历史上的今天'}# 地址栏不允许使用中文 遇到中文需要进行编码# 编码enc = parse.urlencode(query) # 传入字典print('enc', enc, type(enc))enc = parse.quote('kw=历史上的今天') # 传入字符串 这个会把等于号也进行处理print('enc'原创 2021-11-26 20:46:42 · 119 阅读 · 0 评论 -
存储数据库Redis-行政区划代码-5级12位-最终版
import jsonimport osimport timeimport redisjoinStr = '\n'fileSep = ','fileDataEncoding = 'utf-8'def timePlus(): t = time.time() return '%s %.4f' % (time.strftime('%H:%M:%S', time.localtime(t)), t - int(t))def getFileData(filePath)原创 2021-11-26 16:29:16 · 410 阅读 · 0 评论 -
存储数据库MongoDB-行政区划代码-5级12位-最终版
# CY3761 | 2021-11-20 23:52import osimport timeimport pymongojoinStr = '\n'fileSep = ','fileDataEncoding = 'utf-8'def timePlus(): t = time.time() return '%s %.4f' % (time.strftime('%H:%M:%S', time.localtime(t)), t - int(t))def ge原创 2021-11-26 15:31:33 · 697 阅读 · 0 评论 -
存储数据库MYSQL-行政区划代码-5级12位-最终版
# CY3761 | 2021-11-20 23:52import osimport timeimport mysql.connector.errorsfrom mysql.connector import connectjoinStr = '\n'fileSep = ','fileDataEncoding = 'utf-8'def timePlus(): t = time.time() return '%s %.4f' % (time.strftime('原创 2021-11-26 08:54:17 · 1165 阅读 · 0 评论 -
行政区划代码-5级12位-单线程声明类版本(最终版)
经过一整天加上昨晚的部分执行,至于出炉了代码# CY3761 | 2021-11-19 17:55# 行政区划代码-5级12位-单线程对象版本# 导航: 统计数据 -> 统计标准 -> 统计用区划和城乡划分代码# 爬取初始网址: [获取最新数据链接](http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm)## 内含5种布局# md表格: 表头的下一行中横线最少3个一格# md表格: 表头的下一行, 使用冒号进行对齐"""序号原创 2021-11-20 18:00:17 · 492 阅读 · 2 评论 -
行政区划代码-5级12位-scrapy版(二)
续集import jsonimport os.pathimport timeimport scrapyfrom pyquery import PyQuery as pqfrom scrapy import Requestfrom ..settings import *class CodeSpider(scrapy.Spider): name = 'code' allowed_domains = ['www.stats.gov.cn'] # start_ur原创 2021-11-20 10:30:27 · 243 阅读 · 0 评论 -
xpath与pyquery哪个好?
# CY3761 | 2021-11-19 12:22import requestsfrom lxml import etreefrom pyquery import PyQuery as pqheaders = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/95.0.4638.69原创 2021-11-19 14:05:14 · 432 阅读 · 0 评论 -
行政区划代码-5级12位-scrapy版(一)
CY3761 | 2021-11-18 10:18行政区划代码-5级12位-scrapy版本导航: 统计数据 -> 统计标准 -> 统计用区划和城乡划分代码爬取初始网址: 获取最新数据链接内含5种布局序号代码个数class前缀111 00 00 000 00000000province211 01 00 000 00000000city311 01 01 000 00000000county411 01 01 001 0原创 2021-11-18 16:43:18 · 683 阅读 · 1 评论 -
将糗事百科爬虫部署到服务器centos
修改配置文件 部署到 centos# settings.py# 增加下面两句内容# REDIS 配置REDIS_HOST = '192.168.31.50' # 127.0.0.1 只能本机使用 如需多台服务器使用, 需要能够连通的主机REDIS_PORT = 6379获取redis 服务器ipredis配置# 配置 redis.windows-service.confbind 0.0.0.0protected-mode nobind 0.0.0.0 # 监听所有网络pro原创 2021-11-17 20:58:30 · 1359 阅读 · 0 评论 -
使用scrapy爬取糗事百科的的段子,并保存到redis
爬取的初始网址是: https://www.qiushibaike.com/text/page/1/首先需要创建项目cd 目录路径进入到对应的目录然后使用下面的代码进行创建 scrapy 项目# 项目名: qsbkscrapy startproject qsbk进入目录 qsbk , 并使用crawl模版创建爬虫文件# -t crawl | 使用 crawl模版# text | 爬虫文件名 执行爬虫的名字# www.qiushibaike.com | 爬虫允许的域名scrapy ge原创 2021-11-17 17:04:42 · 639 阅读 · 0 评论