随笔分类 -  Python编程快速上手

读书笔记
正则表达式 运用
摘要:从剪贴板中查找美国电话号码和电子邮件,并在屏幕打印。 import re import pyperclip #为电话创建正则表达式 phoneRegex = re.compile(r'''( (\d{3}|\(\d{3}\))? #区号 (\s|-|\.)? #分隔符 (\d{3}) #前三位 (\ 阅读全文

posted @ 2020-02-24 01:16 winecork 阅读(149) 评论(0) 推荐(0)

pyperclip模块
摘要:安装pyperclip模块 pip install pyperclip 导入pyperclip模块后,复制文本“hello world”,打印现在剪切板上的内容“hello world” 阅读全文

posted @ 2019-11-02 16:48 winecork 阅读(214) 评论(0) 推荐(0)

项目:搜索查找
摘要:需求: 每次打开搜索引擎搜索一个关键字,都不会一次只看一个搜索结果。会分别打开前几个链接。即:打开浏览器,搜索关键字,在搜索结果中分别打开各个链接 为简化这个过程,实现通过命令行方式打开结果中的前5个链接 分析: 1.从命令行参数中获取查询关键字; 2.取得查询结果页面; 3.为每个结果打开一个浏览 阅读全文

posted @ 2019-04-24 00:48 winecork 阅读(138) 评论(0) 推荐(0)

使用BeautifulSoup模块解析HTML(文件example.html)
摘要:原文: 代码: 输出: 阅读全文

posted @ 2019-04-23 21:03 winecork 阅读(402) 评论(0) 推荐(0)

使用BeautifulSoup模块解析HTML
摘要:问题: 解决方法: 《CSS选择器的例子》,select()方法将返回一个Tag对象的列表 阅读全文

posted @ 2019-04-23 01:36 winecork 阅读(2737) 评论(0) 推荐(0)

模块requests
摘要:import requests # 1.调用requests.get()下载该文件 # 2.用'wb'调用open(),以写二进制的方式打开一个新文件 # 3.利用Response对象的iter_content()方法写入该文件 # 4.在每次迭代中调用write(),将内容写入该文件 # 5.调用close()方法关闭该文件 #使用requests.get()函数下载一个网页 res ... 阅读全文

posted @ 2019-04-23 00:01 winecork 阅读(149) 评论(0) 推荐(0)

mapIt.py
摘要:不打开浏览器,直接加载搜索关键的网站 安装模块 pip install webbrowser pip install pyperclip 文件:mapIt.py 阅读全文

posted @ 2019-04-22 23:09 winecork 阅读(104) 评论(0) 推荐(0)

maketrans与translate函数
摘要:ccbba 阅读全文

posted @ 2017-09-19 16:54 winecork 阅读(124) 评论(0) 推荐(0)

使用pip下载/安装python模块
摘要:pip安装pyperclip模块 阅读全文

posted @ 2017-09-03 18:05 winecork 阅读(269) 评论(0) 推荐(0)

方法ljust/rjust/center
摘要:dict = {'apple':4,'banana':10,'pear':8} def printItem(dictName,leftwidth,rightwidth): print("Menu".center(leftwidth+rightwidth,'-')) for i,k in dictName.items(): print(i.ljust(leftwi... 阅读全文

posted @ 2017-09-03 16:43 winecork 阅读(98) 评论(0) 推荐(0)

字符串计数
摘要:import pprint text = "aaaa bbbb ccc dd ee ff gg h i j kkkk" count = {} for i in text: count.setdefault(i,0) count[i] = count[i] + 1 # pprint.pprint(count) print(pprint.pformat(count)) 阅读全文

posted @ 2017-09-03 15:51 winecork 阅读(99) 评论(0) 推荐(0)

导航