实习日志2

吃草阶段,未消化
1.python常见编码问题
u”类型

a=u'\xe5\x9c\xa3\xe5\xbd\xbc\xe5\xbe\x97\xe5\xa0\xa1\xe6\x8e\x92\xe5\x90\x8d\xe7\xac\xac 1 \xe9\xa4\x90\xe5\x8e\x85 (\xe5\x85\xb1 8,650 \xe9\x97\xb4)'
print a
print a.encode('raw-unicode-escape')

处理\u00类型的编码

>>> a = u'\u00e6\u0097\u00a5\u00e6\u009c\u00ac\u00e5\u009f\u00bc\u00e7\u008e\u0089\u00e5\u00b8\u0082\n'
>>> print a
>>> print a.encode('iso-8859-1').decode('utf-8')

\uxxxx解码

a='\u56e0'
print a.decode('unicode-escape')

如果是str的过程

a = '\u00e6\u0097\u00a5\u00e6\u009c\u00ac\u00e5\u009f\u00bc\u00e7\u008e\u0089\u00e5\u00b8\u0082'
print a.decode('unicode-escape').encode('iso-8859-1').decode('utf8')

unicode+ascii,且u前没有\

#coding=utf8
s = 'u00e7u0088u00b1u00e5u00b0u0094u00e7u00a6u008fu00e7u0089u00b9u00e5u009fu008eu00e9u0099u0085u00e9u0085u0092u00e5u00bau0097u00e6u0098u00afu00e4u00b8u0080u00e5u00aeu00b6u00efu00bcu008cu00e8u00b7u009du00e7u00a6u00bbu00e5u00aeu0089u00e6u00a0u00bcu00e5u00b0u0094u00e5u008du009au00e7u0089u00a9u00e9u00a6u0086u00e5u0092u008cu00e5u0085u008bu00e9u009bu00b7u00e9u00bbu0098u00e6u00a1u00a5u00e4u00b8u008du00e5u0088u00b0 15 u00e5u0088u0086u00e9u0092u009fu00e7u009au0084u00e6u00adu00a5u00e8u00a1u008cu00e8u00b7u00afu00e7u00a8u008bu00e3u0080u0082u00e8u0080u008cu00e4u00b8u0094u00efu00bcu008cu00e8u00bfu0099u00e5u00aeu00b6u00e9u0085u0092u00e5u00bau0097u00e8u00b7u009du00e7u00a6u00bbu00e5u009fu0083u00e5u00b0u0094u00e7u00a6u008fu00e7u0089u00b9u00e5u00a4u00a7u00e6u0095u0099u00e5u00a0u0082u00e5u0092u008cEgapark Erfurtu00e4u00b8u008du00e5u0088u00b0 5 u00e5u0085u00acu00e9u0087u008cu00e3u0080u0082 u00e6u00adu00a4u00e9u0085u0092u00e5u00bau0097u00e6u008fu0090u00e4u00beu009bu00e9u00a4u0090u00e5u008eu0085u00e3u0080u0081u00e5u00b1u008bu00e9u00a1u00b6u00e9u009cu00b2u00e5u008fu00b0u00e5u0092u008cu00e5u00b9u00b2u00e6u00b4u0097/u00e6u00b4u0097u00e8u00a1u00a3u00e6u009cu008du00e5u008au00a1u00e3u0080u0082u00e5u00a6u0082u00e6u009eu009cu00e6u0082u00a8u00e6u0083u00b3u00e5u0096u009du00e6u009du00afu00e9u00a5u00aeu00e6u0096u0099u00e6u0094u00beu00e6u009du00beu00e4u00b8u0080u00e4u00b8u008bu00efu00bcu008cu00e9u0085u0092u00e5u0090u00a7/u00e9u0085u0092u00e5u00bbu008au00e7u00bbu009du00e5u00afu00b9u00e6u0098u00afu00e6u0082u00a8u00e7u009au0084u00e5u00a5u00bdu00e5u008eu00bbu00e5u00a4u0084u00e3u0080u0082'

if __name__ == '__main__':
    import re

    pattern = re.compile(r'((u00([a-z0-9]){2})+)')
    for i in pattern.findall(s):
        s = s.replace(i[0], i[0].replace('u', '\\u').decode('unicode-escape').encode('iso-8859-1'))

2.str.format()用法

3.import json

4.import execjs

5.time

time.strftime(DATE_F,ti)

6.requests
http://docs.python-requests.org/zh_CN/latest/user/advanced.html#advanced

7.python 操作csv

8.并发&异步&多进程&多线程
异步I/O所有的异步I/O都依赖于同一种模式.它不在于代码如何运行,而在于在何处完成等待.多路I/O操作需要统一做等待处理,于是,等待只在代码中的一个地方出现.当事件触发的时候,异步系统需要恢复等待这个事件的代码块.
http://www.361way.com/python-gevent/5329.html
接下来的问题不在于在一个地方做等待,而在于如何恢复等待接收事件的代码块.

gevent 与 pymysql 相比 MySQLdb更好的解决阻塞问题
monkey patch一般在使用gevent程序的最开头的地方会加入gevent.monkey.patch_all() ,其作用是把标准库中的thread/socket等给替换掉

pymysql 连接池

Python 多线程和多进程编程总结
https://tracholar.github.io/wiki/python/python-multiprocessing-tutorial.html

9.迭代器
http://pyzh.readthedocs.io/en/latest/the-python-yield-keyword-explained.html#id3

>>> horses = [1, 2, 3, 4]
>>> races = itertools.permutations(horses)
>>> print(races)
<itertools.permutations object at 0xb754f1dc>
>>> print(list(itertools.permutations(horses)))

10.shell 编程

10.5 git
http://www.ruanyifeng.com/blog/2014/06/git_remote.html

11.Mechanize module & abc module

12.python 异常处理

13.Django

14.机器人验证
http://www.checkupdown.com/status/E400_zh.html

15.lxml
http://lxml.de/index.html

16.JS反反爬虫解析问题

17.Designing a RESTful API with Python and Flask
https://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask
flask:
http://docs.jinkan.org/docs/flask/quickstart.html#quickstart

18.容器(Collections)
https://eastlakeside.gitbooks.io/interpy-zh/content/collections/collections.html

19.XPath
<>———————————<>
写不完的部分:
dive into python
http://www.diveintopython.net/
1.list越长,耗时越长。
如果用dict实现,只需要一个key-value的对照表,直接根据key查找value,无论这个表有多大,查找速度都不会变慢。
原因:
List遍历去查找内容。dict通过遍历

2.模块: collections. http://www.zlovezl.cn/articles/collections-in-python/

3.爬虫设计逻辑:
1)任务信息->class Task(object)
2)设计爬虫->class spider 按需设置框架和子爬虫
3)设计日志修饰器,修饰每一个函数,方便梳理与查找Bug
4)设计代理->class MechanizeCrawler(object)
5)对目标请求获取回应和数据解析
6)针对不同错误返回不同的代码进行分析

4.pygame

5.偶发一个有趣的网站http://www.pythonchallenge.com/

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值