问题描述
Python安装在我电脑上的磁盘C上:C:我的电脑上安装了twill(之前安装了Python 2.5),并且最近一直在使用它。 :\Python25
斜纹文件夹(twill-0.9)位于这里:E:\ tmp\twill-0.9
以下是我一直使用的代码:
go某些网站的登录页面URL
formvalue 2 userid我的登录名
formvalue 2通过我的密码
提交
转到来自该网站的其他某个网页的网址
save_html result.txt
这段代码可以帮助我登录到一个网站,一个帐户,记录该网站其他页面的HTML代码(只有在登录后才能访问),并将其存储在名为result.txt的文件中(当然,在使用此代码之前,我首先需要替换我的登录与我的真实登录,我的密码与我的真实密码,某网站的登录页面URL和该网站的某个其他网页的网址,以及该网站的真实网址,以及该网站上用作登录表单的该网站上表单的编号2登录页面)
这个代码存储在位于我的twill-0.9文件夹中的test.twill文件中:E:\ tmp \ twill-0.9 \test.twill
我从我的命令提示符下运行这个文件:python twill -sh test.twill
现在,我也安装了 Google App Engine SDK,并且也一直在使用它。
例如,我一直在使用这段代码:
导入hashlib
m = hashlib.md5()
m.update(没有人检查)
m.update(垃圾重复)
print m.hexdigest()
此代码可帮助我将短语没有人检查垃圾邮件重复转换为md5摘要。
现在,我怎样才能将这两段代码放到一个可以运行在Google App Engine上的Python脚本中?
假设我想要我的代码从Google App Engine登录到一个网站,转到该网站上的另一个页面,记录它的HTML代码(这就是我的斜纹代码所做的),并且将此HTML代码转换为它的md5摘要(这是我的第二个代码所做的)。那么,如何将这两个代码合并为一个Python代码呢?
我想,应该通过导入twill来以某种方式完成,但怎么做呢?是否可以使用Python代码 - 由Google App Engine运行的代码 - 从互联网上某处导入斜纹?或者,也许斜纹已经安装在Google App Engine上?
更新1:
(此更新是我对Wooble答案的回应)
以下是所有文件夹的列表(在我的twill-0.9文件夹中)包含 __ init
__。py文件。 (此列表中的某些文件夹位于其他文件夹内,这些文件夹也在本列表中提及):
E:\twill-0.9\build\lib \twill\extensions\match_parse
\twill-0.9\build\lib\twill\extensions
:b $ b
E:\twill-0.9\build\lib\twill\other_packages\_mechanize_dist
E:\twile -0.9 \ build \lib\twill\other_packages
E:\twill-0.9\build\lib\twill
\twill-0.9\twill\extensions\match_parse
E:\twill-0.9\ twill\extensions
E:\twill-0.9\twill\other_packages\_mechanize_dist
E:\twill-0.9\twill\other_packages
E:\twill-0.9\twill
在App Engine项目中使用第三方库,部署时只需将它们包含在应用程序中。将twill文件夹(包含 __ init __。py
)的文件夹复制到应用程序的文件夹中并进行部署。
纵观谷歌代码项目,看起来twill在包中包含它的依赖关系(pyparsing,mechanize等),所以你可能不需要包含任何东西其他。
I have installed twill on my computer (having previously installed Python 2.5) and have been using it recently.
Python is installed on disk C on my computer: C:\Python25
And the twill folder ("twill-0.9") is located here: E:\tmp\twill-0.9
Here is a code that I’ve been using in twill:
go "some website’s sign-in page URL"
formvalue 2 userid "my login"
formvalue 2 pass "my password"
submit
go "URL of some other page from that website"
save_html result.txt
This code helps me to log in to one website, in which I have an account, record the HTML code of some other page of that website (that I can access only after logging in), and store it in a file named "result.txt" (of course, before using this code I firstly need to replace "my login" with my real login, "my password" with my real password, "some website’s sign-in page URL" and "URL of some other page from that website" with real URLs of that website, and number 2 with the number of the form on that website that is used as a sign-in form on that website’s log-in page)
This code I store in "test.twill" file that is located in my "twill-0.9" folder: E:\tmp\twill-0.9\test.twill I run this file from my command prompt: python twill-sh test.twill
Now, I also have installed "Google App Engine SDK" from "Google App Engine" and have also been using it for awhile.
For example, I’ve been using this code:
import hashlib
m = hashlib.md5()
m.update("Nobody inspects")
m.update(" the spammish repetition ")
print m.hexdigest()
This code helps me transform the phrase "Nobody inspects the spammish repetition" into md5 digest.
Now, how can I put these two pieces of code together into one python script that I could run on "Google App Engine"?
Let’s say, I want my code to log in to a website from "Google App Engine", go to another page on that website, record its HTML code (that’s what my twill code does) and than transform this HTML code into its md5 digest (that’s what my second code does). So, how can I combine those two codes into one python code?
I guess, it should be done somehow by importing twill, but how can it be done? Can a python code - the one that is being run by "Google App Engine" - import twill from somewhere on the internet? Or, perhaps, twill is already installed on "Google App Engine"?
Update 1:
(this update is my response to Wooble’s answer)
Here is the list of all folders (in my "twill-0.9" folder) that contain __init
__.py files. (some folders on this list are located inside of other folders, which are also mentioned in this list) :
E:\twill-0.9\build\lib\twill\extensions\match_parse
E:\twill-0.9\build\lib\twill\extensions
E:\twill-0.9\build\lib\twill\other_packages\_mechanize_dist
E:\twill-0.9\build\lib\twill\other_packages
E:\twill-0.9\build\lib\twill
E:\twill-0.9\twill\extensions\match_parse
E:\twill-0.9\twill\extensions
E:\twill-0.9\twill\other_packages\_mechanize_dist
E:\twill-0.9\twill\other_packages
E:\twill-0.9\twill
To use third-party libraries in App Engine projects, you simply have to include them with your application when you deploy. Copy the twill folder (the one containing __init__.py
) into your application's folder and deploy it.
Looking at the twill Google Code project, it appears that twill includes its dependencies (pyparsing, mechanize, etc.) in the package, so you may not need to include anything else.
这篇关于如何将twill和python合并为一个可以在“Google App Engine”上运行的代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!