Tag: Python

  • Hello GSoC 2013! Hello Planet of GNOME!

    Finally landing on the Planet of GNOME! [0] Thanks for Alberto Ruiz’s help and patience! This is the voice from huxuan, the spelling of My Chinese name 扈煊. And my English Name is Sean Hu. So you can call me Sean, Xuan Hu or just huxuan is OK. I am from Beijing, China, a graduate…

  • 虾米自动签到的python脚本

    这个页面已经不再维护更新了,你可以从这里了解最新的进展 一个练手的小脚本,暂时只是实现了签到,还没有很完备的错误处理,而且在实现“全自动签到”上还没有想出什么合理的方案,先把代码贴上现丑了…… 使用方法很简单 [bash] python xiami_auto_checkin.py email password [/bash] 即把用户名(email)和密码作为参数传进去即可 如果你只是签固定的一个帐号,也可以直接将代码中的读参数改成赋值 这个代码只是最初的版本,你可以在这里看到最新的进展 [python] #!/usr/bin/python # encoding:utf-8 import re import sys import urllib import urllib2 import cookielib def check(response): “”” docstring for check “”” pattern = re.compile(r’ (已连续签到\d+天) ‘) result = pattern.search(response) if result: return result.group(1) return False pass def main(): “”” docstring for main “””…

  • 用Python处理xml文件中的非法字符

    用xml.dom.minidom.parse()解析xml文件时遇到非法字符直接报错的问题 最后的方案是把纯文本方式读入文件,然后用字符串来处理 可以得到将非法字符全部剔除的结果 [python] #!/usr/bin/python # -*- coding:utf-8 -*- import string import xml.dom.minidom def parse_xml(file_path): “”” Handle xml file with invalid character [input] : path of the xml file [output] : xml.dom.minidom.Document instance “”” try: xmldoc = xml.dom.minidom.parse(file_path) except: f = file(file_path) s = f.read() f.close() ss = s.translate(None, string.printable) s = s.translate(None, ss) xmldoc…