随笔分类 -  python 面试题

摘要:l1 = ['b','c','d','c','a','a'] l2 = list(set(l1)) print(l2) 阅读全文
posted @ 2019-07-16 01:12 anobscureretreat 阅读(332) 评论(0) 推荐(0)
摘要:list1 = [1,2,3] list2 = [3,4,5] set1 = set(list1) set2 = set(list2) print(set1 & set2) print(set1 ^ set2) 阅读全文
posted @ 2019-07-16 01:11 anobscureretreat 阅读(538) 评论(0) 推荐(0)
摘要:print([x*11 for x in range(10)]) 阅读全文
posted @ 2019-07-16 01:10 anobscureretreat 阅读(664) 评论(0) 推荐(0)
摘要:放慢抓取熟速度,减小对目标网站造成的压力,但是这样会减少单位时间内的数据抓取量 使用代理IP(免费的可能不稳定,收费的可能不划算) 阅读全文
posted @ 2019-07-16 01:08 anobscureretreat 阅读(338) 评论(0) 推荐(0)
摘要:通过headers反爬虫:自定义headers,添加网页中的headers数据。 基于用户行为的反爬虫(封IP):可以使用多个代理IP爬取或者将爬取的频率降低。 动态网页反爬虫(JS或者Ajax请求数据):动态网页可以使用 selenium + phantomjs 抓取。 对部分数据加密处理(数据乱 阅读全文
posted @ 2019-07-16 01:01 anobscureretreat 阅读(744) 评论(0) 推荐(0)
摘要:headers方向判断User-Agent、判断Referer、判断Cookie。将浏览器的headers信息全部添加进去注意:Accept-Encoding;gzip,deflate需要注释掉 阅读全文
posted @ 2019-07-16 00:53 anobscureretreat 阅读(425) 评论(0) 推荐(0)
摘要:网络数据包 urllib、urllib2、requests 解析包 re、xpath、beautiful soup、lxml 阅读全文
posted @ 2019-07-16 00:51 anobscureretreat 阅读(943) 评论(0) 推荐(0)
摘要:保存当前运行状态,然后暂停执行,即将函数挂起。yield关键字后面表达式的值作为返回值返回。当使用next(),send()函数从断点处继续执行。 阅读全文
posted @ 2019-07-16 00:48 anobscureretreat 阅读(497) 评论(0) 推荐(0)
摘要:输出 阅读全文
posted @ 2019-07-16 00:29 anobscureretreat 阅读(206) 评论(0) 推荐(0)
摘要:Python之禅import this 阅读全文
posted @ 2019-07-16 00:26 anobscureretreat 阅读(207) 评论(0) 推荐(0)
摘要:输出 阅读全文
posted @ 2019-07-16 00:23 anobscureretreat 阅读(282) 评论(0) 推荐(0)
摘要:删除文件 path,删除时候如果path是一个目录, 抛出 OSError错误。 remove() 同 unlink() 的功能是一样的 如果remove文件夹就会报错 现在删除下面这个文件 删除xx.txt os.removedirs(path),删除文件夹,但是文件夹必须为空。 递归地删除目录。 阅读全文
posted @ 2019-07-16 00:18 anobscureretreat 阅读(16521) 评论(0) 推荐(0)
摘要:输出 阅读全文
posted @ 2019-07-15 21:37 anobscureretreat 阅读(11697) 评论(0) 推荐(0)
摘要:a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] b = filter(lambda x: x % 2 != 0, a) for i in b: print(i) 阅读全文
posted @ 2019-07-15 18:28 anobscureretreat 阅读(548) 评论(0) 推荐(0)
摘要:a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] b = [i for i in a if i % 2 != 0] print(b) 阅读全文
posted @ 2019-07-15 18:26 anobscureretreat 阅读(1140) 评论(0) 推荐(0)
摘要:输出 阅读全文
posted @ 2019-07-15 18:21 anobscureretreat 阅读(682) 评论(0) 推荐(0)
摘要:var = 5 def func(): global var var = 6 print(6) 阅读全文
posted @ 2019-07-15 18:14 anobscureretreat 阅读(464) 评论(0) 推荐(0)
摘要:输出 阅读全文
posted @ 2019-07-15 18:09 anobscureretreat 阅读(506) 评论(0) 推荐(0)
摘要:num = 'Hello world'.count('l') 阅读全文
posted @ 2019-07-15 17:57 anobscureretreat 阅读(253) 评论(0) 推荐(0)
摘要:封装一个原本重复使用的正则表达式 阅读全文
posted @ 2019-07-15 17:56 anobscureretreat 阅读(823) 评论(0) 推荐(0)