摘要: pip install python.docx from docx import DocumentDoc = Document() 解释:from 从 docx这个文件中,导入一个叫Document的一个东西,Document是文档的意思,所以它是对word文档进行操作的一个玩意. 在下面Doc = 阅读全文
posted @ 2020-02-17 07:14 myrj 阅读(195) 评论(0) 推荐(0)
摘要: import requests rr=requests.get("https://api.github.com",auth=('user','pass')) print(rr.status_code) print(rr.headers['content-type']) 结果: RESTART: D: 阅读全文
posted @ 2020-02-16 18:19 myrj 阅读(140) 评论(0) 推荐(0)
摘要: urls=[f'https://www.baidu.com/?page={page}' for page in range(1,5)] #F f大小写都可以 print(urls) page=10 url='https://www.baidu.com/?page={}'.format(page) p 阅读全文
posted @ 2020-02-16 16:43 myrj 阅读(201) 评论(0) 推荐(0)
摘要: >>> b=(page for page in range(10))>>> print(b)<generator object <genexpr> at 0x0000000002EE61C8>>>> list(b) #只能生成一次[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>>> l 阅读全文
posted @ 2020-02-16 16:32 myrj 阅读(453) 评论(0) 推荐(0)
摘要: >>> a=[page for page in range(10)]>>> print (a)[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>>> a=[page*2 for page in range(10)]>>> print(a)[0, 2, 4, 6, 8, 10, 12, 1 阅读全文
posted @ 2020-02-16 16:24 myrj 阅读(158) 评论(0) 推荐(0)
摘要: //img/@src 得到所有img标签的src值 //a/text() 得到所有A标签中的文本 name=response.xpath('//img@src').getall() #getall()从对象中获取具体值 import requests,re from lxml import etre 阅读全文
posted @ 2020-02-16 16:00 myrj 阅读(225) 评论(1) 推荐(0)
摘要: r'[\u4e00-\u9fa5]汉字 .匹配除换行符外的任意字符 \d匹配所有数字 ,与[0-9]相同[0123456789] \D匹配非数字字符,[^0-9] \w匹配数字,字母,下划线[0-9a-zA-Z_] \W匹配非数字 字线 下划线[^0-9A-Za-z] \s匹配任意空白符(空格 换行 阅读全文
posted @ 2020-02-14 20:18 myrj 阅读(129) 评论(0) 推荐(0)
摘要: 执行过程中出错,复制错误信息,利用TRY得到相应的错误,并用特别方法解决: print(3/0)提示: Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> print(3/0)ZeroDivisionE 阅读全文
posted @ 2020-02-14 18:15 myrj 阅读(164) 评论(0) 推荐(0)
摘要: import itertools mylist=list(itertools.permutations([1,2,3,4],3)) #排列 print(mylist) print(len(mylist)) mylist=list(itertools.combinations([1,2,3,4],3) 阅读全文
posted @ 2020-02-14 17:41 myrj 阅读(181) 评论(0) 推荐(0)
摘要: import os def file_name(file_dir): for root, dirs, files in os.walk(file_dir): print(root) #当前目录路径 print(dirs) #当前路径下所有子目录 print(files) #当前路径下所有非目录子文件 阅读全文
posted @ 2020-02-13 14:47 myrj 阅读(596) 评论(0) 推荐(0)