- 博客(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 jsondict = {'err_no': 0,'err_str': 'OK', 'pic_id': ..
2022-02-20 17:20:49
5076
原创 使用python提取JSON数据指定内容
假设我们要获取'pic_str'里的数据JSON数据{'err_no': 0, 'err_str': 'OK', 'pic_id': '1169213517976400008', 'pic_str': 'xoet', 'md5': 'ca9bc4fda521498d2b3aba5dbb4ee4ac'}1、JSON数据为字符串类型import jsonstr = "{'err_no': 0, 'err_str': 'OK', 'pic_id': '116921351797.
2022-02-20 15:33:32
23126
1
原创 利用re模块爬取煎蛋网美女图(菜单改良升级版)
我爬取的是原图,比页面的图片清楚一些,而且可以连续爬取多个页面的图片效果图:源代码:import requestsimport reimport osfrom prettytable import PrettyTableimg_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
399
原创 利用requests, xpath爬取站长网简历模板
导入模块:requests, lxml, osimport requestsfrom lxml import etreeimport 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
631
原创 如何用request模块下载rar, zip文件
import requestsurl = 'https://downsc.chinaz.net/Files/DownLoad/jianli/202201/jianli16910.rar'r = requests.get(url).contentwith open('demo1.rar','wb') as fp:fp.write(r)注意:网页编码格式要使用二进制格式,即使用content 采用get获取网页 写入格式使用二进制,即'wb'...
2022-02-16 14:42:40
973
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
461
原创 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
1912
原创 爬虫中文乱码问题解决方案
method 1:Using response.enconding mathodresponse = 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
691
csv文件下载(人员信息.txt)
2022-07-04
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人