/image/avatar.png

使用web.py在BAE建立自已的电影网站

最近在网上看了一篇文章使用web.py在BAE上建立电影网站,http://www.51bigfool.com/%E6%88%91%E6%98%AF%E5%A6%82%E4%BD%95%E7%94%A8bae%E5%92%8Cweb-py%E6%89%93%E9%80%A0%E8%B1%86%E7%93%A3%E7%94%B5%E5%BD%B1top100%E7%9A%84.html 我自已也在此基础上做了一些改进,也在一点点的熟悉使用web.py这个框架,可以看一下我弄了一半的应用 http://movie.yangyanxing.com

准备 BAE web.py

在BAE上建立一个python的应用

快速创建即可,选择Iframe

/image/2013/11/create_thumb.jpg
create

web.py中关于url的总结

网页中的数据在传递的时候有GET和POST两种方式,GET是以网址的形式传参数,在web.py中有着很好的匹配,如果我们配置以下的urls

1
2
3
  urls =(
    '/','index',
    '/weixin/(.*?)','WeixinInterface'

先不考虑/weixin/后面的东西,现在我们来写index的类

1
2
3
class index:
    def GET(self):
        i = web.input(name = 'kevinkelin',age = 100)

在中文windows下使用pywinauto进行窗口操作(一)

这两天开始接触pywinauto,听说百度的自动化QA也用这个模块,于是来了兴趣,但网上的教程很少,而且基本上都是拿官方的notepad来说,首先中文菜单的支持是问题,其次各种操作也没有写清楚,阅读官方的文档,发现这个东西使用起来还真是非常方便,下面我也以notepad为例来说明一下它的简单操作。

安装

pywinauto;

https://sourceforge.net/project/showfiles.php?group_id=157379

Sendkeys

http://www.rutherfurd.net/python/sendkeys/index.html

ctypes (如果你是python2.3或者2.4)

检测你是否安装正确

from pywinauto import application app = application.Application.start(“notepad.exe”) app.notepad.TypeKeys("%FX")

使用python进行windows自动化测试(1)

最近开始学习整理python在windows自动化测试中的使用,觉得挺有意思的

主要思路,在windows下,主要通过启进程,然后查找进程的句柄,然后再操作这个句柄,包括点击,填写文字,关闭,获取文字等操作

下面以一个简单的校验文件md5值的操作来介绍一个python的应用,当然python中有校验md5的函数,不用非要使用工具来校验,这里只是练习使用python来自动化操作

所用的工具有SpyLite,用于查看窗口ID,句柄等信息

Python中的urllib2库的使用

今天研究了下urllib2这个库的使用,才发现以前有很多不明白的东西,现在写下来也做个记录

最基础的应用

1
2
3
import urllib2
url = r'http://www.baidu.com'
html = urllib2.urlopen(url).read()

客户端与服务器端通过request与response来沟通,客户端先向服务端发送request,然后接收服务端返回的response

urllib2提供了request的类,可以让用户在发送请求前先构造一个request的对象,然后通过urllib2.urlopen方法来发送请求

1
2
3
4
import urllib2
url = r'http://www.baidu.com'
req = urllib2.Request(url)
html = urllib2.urlopen(req).read()

python处理网页中的cookie

最近想要搭建个小黄鸡的微信应用,但是一路来发现,现在很多的方法都已经不能用了,我在本地试过,也试用过requests获取session的方法也不行,但是这经过这次折腾,倒是对cookie有了更多的了解,以下以python登录人人网的例子来介绍cookie的使用。 cookie的定义可以参考百度百科,http://baike.baidu.com/subview/835/5062332.htm 但是里面说的乱七八糟的,而且好多重复,使用firefox或者fiddler等工具来抓取cookie 在firefox下使用httpFox插件来查到人人网的登录时需要POST的地址是http://www.renren.com/ajaxLogin 

/image/2013/09/getUrl_thumb.png
getUrl

python解析json

相对于python解析XML来说,我还是比较喜欢json的格式返回,现在一般的api返回都会有json与XML格式的选择,json的解析起来个人觉得相对简单些

先看一个简单的豆瓣的图书查询的api返回

Python解析XML文档

解析XML主要用到pytohn自带的XML库,其次还是lxml库

XML结构

先以一个相对简单但功能比较全的XML文档为例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?xml version='1.0' encoding='utf-8'?>
<feed xmlns='http://www.w3.org/2005/Atom' xml:lang='en'>
  <title>dive into mark</title>
  <subtitle>currently between addictions</subtitle>
  <id>tag:diveintomark.org,2001-07-29:/</id>
  <updated>2009-03-27T21:56:07Z</updated>
  <link rel='alternate' type='text/html' href='http://diveintomark.org/'/>
  <entry>
    <author>
      <name>Mark</name>
      <uri>http://diveintomark.org/</uri>
    </author>
    <title>Dive into history, 2009 edition</title>
    <link rel='alternate' type='text/html'
      href='http://diveintomark.org/archives/2009/03/27/dive-into-history-2009-edition'/>
    <id>tag:diveintomark.org,2009-03-27:/archives/20090327172042</id>
    <updated>2009-03-27T21:56:07Z</updated>
    <published>2009-03-27T17:20:42Z</published>
    <category scheme='http://diveintomark.org' term='diveintopython'/>
    <category scheme='http://diveintomark.org' term='docbook'/>
    <category scheme='http://diveintomark.org' term='html'/>
    <summary type='html'>Putting an entire chapter on one page sounds
      bloated, but consider this &mdash; my longest chapter so far
      would be 75 printed pages, and it loads in under 5 seconds&hellip;
      On dialup.</summary>
  </entry>
  <entry>
    <author>
      <name>Mark</name>
      <uri>http://diveintomark.org/</uri>
    </author>
    <title>Accessibility is a harsh mistress</title>
    <link rel='alternate' type='text/html'
      href='http://diveintomark.org/archives/2009/03/21/accessibility-is-a-harsh-mistress'/>
    <id>tag:diveintomark.org,2009-03-21:/archives/20090321200928</id>
    <updated>2009-03-22T01:05:37Z</updated>
    <published>2009-03-21T20:09:28Z</published>
    <category scheme='http://diveintomark.org' term='accessibility'/>
    <summary type='html'>The accessibility orthodoxy does not permit people to
      question the value of features that are rarely useful and rarely used.</summary>
  </entry>
  <entry>
    <author>
      <name>Mark</name>
    </author>
    <title>A gentle introduction to video encoding, part 1: container formats</title>
    <link rel='alternate' type='text/html'
      href='http://diveintomark.org/archives/2008/12/18/give-part-1-container-formats'/>
    <id>tag:diveintomark.org,2008-12-18:/archives/20081218155422</id>
    <updated>2009-01-11T19:39:22Z</updated>
    <published>2008-12-18T15:54:22Z</published>
    <category scheme='http://diveintomark.org' term='asf'/>
    <category scheme='http://diveintomark.org' term='avi'/>
    <category scheme='http://diveintomark.org' term='encoding'/>
    <category scheme='http://diveintomark.org' term='flv'/>
    <category scheme='http://diveintomark.org' term='GIVE'/>
    <category scheme='http://diveintomark.org' term='mp4'/>
    <category scheme='http://diveintomark.org' term='ogg'/>
    <category scheme='http://diveintomark.org' term='video'/>
    <summary type='html'>These notes will eventually become part of a
      tech talk on video encoding.</summary>
  </entry>
</feed>

先简单的看一下这个XML的结构