- 博客(9)
- 资源 (1)
- 收藏
- 关注
原创 用python将单引号替换为双引号
1、若对象为字符串 str = "{'err_no': 0,'err_str': 'OK', 'pic_id': '1169213517976400008', 'pic_str': 'xoet', 'md5': 'ca9bc4fda521498d2b3aba5dbb4ee4ac'}" json_str = str.replace("'",'"') 2、若对象为字典 imort json dict = {'err_no': 0,'err_str': 'OK', 'pic_id': ..
2022-02-20 17:20:49
5680
原创 使用python提取JSON数据指定内容
假设我们要获取'pic_str'里的数据 JSON数据 {'err_no': 0, 'err_str': 'OK', 'pic_id': '1169213517976400008', 'pic_str': 'xoet', 'md5': 'ca9bc4fda521498d2b3aba5dbb4ee4ac'} 1、JSON数据为字符串类型 import json str = "{'err_no': 0, 'err_str': 'OK', 'pic_id': '116921351797.
2022-02-20 15:33:32
25313
1
原创 利用re模块爬取煎蛋网美女图(菜单改良升级版)
我爬取的是原图,比页面的图片清楚一些,而且可以连续爬取多个页面的图片 效果图: 源代码: import requests import re import os from prettytable import PrettyTable img_rule = re.compile(r'<p><a href="(.*?)" target="_blank" class="view_img_link"',re.S) next_rule = re.compile...
2022-02-18 22:22:11
479
原创 利用requests, xpath爬取站长网简历模板
导入模块:requests, lxml, os import requests from lxml import etree import os # 创建一个文件夹 def mkdir(path): isExists = os.path.exists(path) if not isExists: print('创建名字叫做', path, '的文件夹') os.makedirs(path) # 获取htm链接,并返回一个完整的htm链接,获取标题 .
2022-02-16 15:23:59
713
原创 如何用request模块下载rar, zip文件
import requests url = 'https://downsc.chinaz.net/Files/DownLoad/jianli/202201/jianli16910.rar' r = requests.get(url).content with open('demo1.rar','wb') as fp: fp.write(r) 注意:网页编码格式要使用二进制格式,即使用content 采用get获取网页 写入格式使用二进制,即'wb' ...
2022-02-16 14:42:40
1203
2
原创 快速创建一个文件夹
def mkdir(path): isExists = os.path.exists(path) if not isExists: print('创建名字叫做', path, '的文件夹') os.makedirs(path) This function is used to quickly create a folder, to savefiles.
2022-02-11 10:48:33
590
原创 Xpath中text()方法获取列表为空问题解决方法
When we use XPath to crawl web pages, we may encounter such a problem: the list printed using the text method is empty, whichcan be caused by non specified direct content. attention:text() method can only get direct content, string(.) can get whole conte.
2022-02-10 22:33:43
2154
原创 爬虫中文乱码问题解决方案
method 1: Using response.enconding mathod response = requests.get(url=url, headers=headers) response.encoding = 'utf-8' If this method has no effect, then trying the following general solution. method 2: First encode 'iso-8859-1' and then decode..
2022-02-10 20:33:50
770
csv文件下载(人员信息.txt)
2022-07-04
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅