使用perl上传文件

时间:2012-06-12 16:15:22

标签: perl upload automation

您能否建议一些方法来完成将文件上传到网站的任务。 单击“上载”按钮,将打开文件浏览窗口。选择文件时,会上传。 没有页面刷新

这是上传按钮的html代码:

<div id="upload-import-link" class="qq-upload-button string-file-import" style="position: relative; overflow: hidden; direction: ltr;">
<input type="file" multiple="multiple" name="file" style="position: absolute; right: 0pt; top: 0pt; font-family: Arial; font-size: 118px; margin: 0pt; padding: 0pt; cursor: pointer; opacity: 0;">
</div>

这是点击上传按钮的POST请求/响应:

响应标题

Connection  keep-alive
Content-Encoding    gzip
Content-Length  97
Content-Type    text/html
Date    Tue, 12 Jun 2012 16:10:46 GMT
Server  Apache
Vary    Accept-Encoding

请求标题

Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection  keep-alive
Content-Length  51
Content-Type    application/octet-stream
Cookie  __utma=15051113.842126841.1338136284.1339431202.1339515554.17; __utmz=15051113.1338136284.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmv=15051113.customer|1=l=%2Fstring%2Fauth%2Fform%2F=1; mp_super_properties=%7B%22all%22%3A%20%7B%22%24initial_referrer%22%3A%20%22http%3A//mygengo.com/string/auth/form/%22%2C%22%24initial_referring_domain%22%3A%20%22mygengo.com%22%2C%22mp_name_tag%22%3A%20%22hitenny%20%3Chitenny@gmail.com%3E%22%2C%22translator%22%3A%20%220%22%7D%2C%22events%22%3A%20%7B%7D%2C%22funnels%22%3A%20%7B%7D%7D; MintUnique=1; _chartbeat2=z6ana05w3hf1zj7u.1338136288894.1339517190647.00000000000001; myG_last_visit=1338169443; myG_last_activity=1338826430; WRUID=0; ki_u=0e6659b9-ae82-145c-fe0f-662e130e2629; ki_t=1338169390734%3B1338821597245%3B1338826464592%3B3%3B22; MintUniqueMonth=1338476400; myG_myGSession=gSIDOJ%2Bt7MKGDkhsbGvQLBdo6N9w%2BUTX8R8Ab6FXZ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nzJ8vEBIUThH7WGOjNU%252FPSO8beKVYph3tJ9XqwLPTAG9LXrjuQXi1%252B4bthgvUjPxdUhROMeqkkmwLZSfW72JQUfV3Dh5lzmfRLr3yfXDb3WAPTJ265aGApx5fYTb%252B0wkoi6NGh52P0gBWtEU11%252FXEmsrQu8NXVNoU870X8Z%252FW1nXdRJmU8qUNDr8T9S2CVpNJ1VdrfLbhw7eX5BPw8J2AyZnPfGgdxbj7eWk1e%252BbO1PHAx%252FSycAB3ZSm9%252BBUYcGjKefoL0PsauuBtF%252BP42Gb3oJoxPfkWqESeLFlsZsJMy7bs9vN3fymfbOpdg%253D%253D; myG_TrackingID=223.235.210.6031066401324182719160536834612890008944fccde5b5e93f7.44148718; __utmb=15051113.40.10.1339515554; __utmc=15051113; _SUPERFLY_nosample=1
Host    mygengo.com
Referer http://mygengo.com/string/p/perl-test-1/admin/languages/import/en
User-Agent  Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0
X-File-Name 1.php
X-Requested-With    XMLHttpRequest

我探讨了WWW::Selenium等方法。但它有限制,它只适用于Firefox 3等。请提出一些方法来实现这一点。

修改

我试过这段代码:

my $file = 'D:\oDesk\MyGengo Integration\1.php';
my $url = 'http://mygengo.com/string/p/perl-test-1/admin/languages/import/en';
my $req = POST $url, Content_Type => 'form-data', 
                          Content => [
                                      submit => 1,
                                      upfile => [ $file ]
                                     ];
my $response = $ua->request($req);

给出了这个错误:

Can't locate object method "POST" via package "http://mygengo.com/string/p/perl-test-1/admin/languages/import/en" 
(perhaps you forgot to load "http://mygengo.com/string/p/perl-test-1/admin/languages/import/en"?) at D:\oDesk\MyGengo Integration\myGengoIntegration line 124.
(in cleanup) Error requesting http://localhost:5555/selenium-server/driver/:
500 Can't call method "FETCH" on an undefined value

1 个答案:

答案 0 :(得分:1)

您可以使用perl CGI脚本执行此任务。

以下文章详细解释了所有步骤: http://www.sitepoint.com/uploading-files-cgi-perl/