“如何绕过机械化”;含糊不清的错误”;用Python

“如何绕过机械化”;含糊不清的错误”;用Python,python,forms,mechanize,Python,Forms,Mechanize,我正试图通过填写ImageBam的web表单并请求发布来将图像上传到ImageBam 我对urllib2、httplib和多部分内容了解不多。我正在尝试使用机械化模块 但我认为它不应该太复杂,因为它只是一个网络表单,我会填写并发布它 页面,其中上载表单为: 我试图填写的表格: <form name='form' id='form' enctype="multipart/form-data" method="post" action="/sys/upload/save">

我正试图通过填写ImageBam的web表单并请求发布来将图像上传到ImageBam

我对urllib2、httplib和多部分内容了解不多。我正在尝试使用机械化模块 但我认为它不应该太复杂,因为它只是一个网络表单,我会填写并发布它

页面,其中上载表单为:

我试图填写的表格:

<form name='form' id='form' enctype="multipart/form-data" method="post" action="/sys/upload/save">


    <table align="center">
        <tr>
            <td>
                01: <input type="file" name="file[]" size="30"><br>
                02: <input type="file" name="file[]" size="30"><br>
                03: <input type="file" name="file[]" size="30"><br>
                04: <input type="file" name="file[]" size="30"><br>
                05: <input type="file" name="file[]" size="30"><br>
我想一切都很好

给出此输出:

<Browser visiting http://www.imagebam.com/basic-upload
 selected form:
 <form POST http://www.imagebam.com/sys/upload/save multipart/form-data
  <FileControl(file[]=<No files added>)>
  <FileControl(file[]=<No files added>)>
  <FileControl(file[]=<No files added>)>
  <FileControl(file[]=<No files added>)>
  <SelectControl(content_type=[*x, 1, 0])>
  <SelectControl(thumb_size=[*100, 150, 180, 250, 300, 350])>
  <SelectControl(thumb_aspect_ratio=[crop, *resize])>
  <SelectControl(thumb_file_type=[gif, *jpg])>
  <CheckboxControl(thumb_info=[1])>
  <CheckboxControl(gallery_options=[*1])>>
>
误差为

Traceback (most recent call last):
  File "<pyshell#46>", line 1, in <module>
    a["file[]"]=dosya
  File "build\bdist.win32\egg\mechanize\_form.py", line 2780, in __setitem__
    control = self.find_control(name)
  File "build\bdist.win32\egg\mechanize\_form.py", line 3101, in find_control
    return self._find_control(name, type, kind, id, label, predicate, nr)
  File "build\bdist.win32\egg\mechanize\_form.py", line 3183, in _find_control
    raise AmbiguityError("more than one control matching "+description)
AmbiguityError: more than one control matching name 'file[]'
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
a[“文件[]”]=dosya
文件“build\bdist.win32\egg\mechanize\\ u form.py”,第2780行,在setitem中__
control=self.find\u控件(名称)
文件“build\bdist.win32\egg\mechanize\\ u form.py”,第3101行,在find\ u控件中
返回self.\u find\u控件(名称、类型、种类、id、标签、谓词、nr)
文件“build\bdist.win32\egg\mechanize\\ u form.py”,第3183行,在“find”控件中
引发歧义错误(“多个控件匹配”+说明)
歧义错误:多个控件匹配名称“file[]”
我怎样才能解决这个问题

已解决

解决方案:

a、 添加文件(dosya,“文件名”,nr=0)

自动搜索type=file输入并将我的文件添加到第一个输入(nr=0提供)

新问题 在我发送POST数据后(或我认为它发送) 这一页是作为回应而来的

<?xml version='1.0' encoding='utf-8'?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://developers.facebook.com/schema/" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="author" content="ImageBam.com" />
<meta name="description" content="Free Image Hosting and photo sharing. Create an online album with bulk upload tools and share with family and friends." />
<meta name="keywords" content="image hosting, free image hosting, photo sharing, upload photo, free photo gallery, photo host, image gallery" />
<meta name="robots" content="follow" />
<meta name="revisit-after" content="1 days" />
<meta property="fb:admins" content="3433880" />
<link rel="stylesheet" href="http://www.imagebam.com/style.css" type="text/css" />
<link rel="shortcut icon" href="http://www.imagebam.com/favicon.ico" />
<title>Fast, Free Image Hosting - ImageBam</title>
<script type="text/javascript" src="http://www.imagebam.com/JS/imagebam.js"></script>
<script type="text/javascript" src="http://www.imagebam.com/JS/pt.js"></script>
</head>
<body>
<!-- IMAGEBAM HEADER -->
<div class="scrollme">
<div class="abody">
<!-- everything -->
<div class="banner cursor" style="float:left;" onclick='top.location="http://www.imagebam.com"'></div>
<div style="float:right; text-align:right; border:0px solid #f2f2f2; border-top:none; padding-top: 5px; padding-left:3px; padding-right:10px;">
</div>
<div style="clear:left;"></div>
<div class="dtab">
<ul>
<li class="inactive"><a href="/">Multi-Upload</a></li>
<li class="inactive"><a href="/zip-upload">Zip-Upload</a></li>
<li class="inactive"><a href="/basic-upload">Basic Upload</a></li>
<li class="inactive"><a href="/learn-more">Learn More</a></li>
<li class="inactive"><a href="/frequently-asked-questions">FAQ</a></li>
<li class="inactive"><a href="/register">Register</a></li>
<li class="inactive"><a href="/login">Login</a></li>
<li class="inactive"><a href="/premium">Premium</a></li>
</ul>
</div><br />
<!-- Google Code for Imagebam Uploaded Image Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
function img404(ID,fsrc){
    document.getElementById('thumb_404_info').style.display="block";
    document.getElementById("img_"+ID).style.display = "none";
    document.getElementById("alt_"+ID).style.display = "inline";
    setTimeout("reloadImg("+ID+",'"+fsrc+"')", 500);
}

function reloadImg(ID,fsrc){
    mrand = Math.random();
    document.getElementById("img_"+ID).style.display = "inline";
    document.getElementById("alt_"+ID).style.display = "none";
    document.getElementById("img_"+ID).src = fsrc+"?"+mrand;
}


/* ]]> */
</script>
<div class="box_wait" style="text-align:center; display:none;" id="thumb_404_info">Thumbnails that are being processed in the background might not load right away.<br /></div>
<div style="text-align:center; margin-bottom:5px;">
<a href="http://videobam.com" target="_blank" style="font-weight:bold; font-size:22px; text-align:center; color:#0174B3;"><b>NEW!</b> VideoBam.com (HD Video Hosting)</a>
</div>
<fieldset><legend><img src="/img/icons/photos.png" alt="" style="vertical-align:middle; line-height:16px; height:16px; padding-right:5px;" /> All at Once</legend>
<table style="width:100%;"><tr>
<td>
<b>BB-Code</b><br />
<textarea onclick="this.select();" style="width:300px; height:200px;"></textarea>
</td>
<td>
<b>HTML-Code</b><br />
<textarea onclick="this.select();" style="width:300px; height:200px;"></textarea>
</td>
</tr>
</table>
</fieldset>
<!--
<fieldset><legend style='color:green;'><img src='/img/icons/new.png' alt='' style='vertical-align:middle; line-height:16px; height:16px; padding-right:5px;'> NEW! ImageBam Remote Upload Widget</legend>
<b>Webmasters / Mods!</b><br> Allow your users to upload images to ImageBam <b>without leaving your website or forum!</b><br> Add our new <a href="/remote-upload-widget" target="_blank">ImageBam Remote Upload Widget</a> to you website!<br>
Please spread the word! Thank you!
</fieldset>
-->
<div style="text-align:center; margin-bottom:5px;">
<a href="http://videobam.com" target="_blank" style="font-weight:bold; font-size:22px; text-align:center; color:#0174B3;"><b>NEW!</b> VideoBam.com (HD Video Hosting)</a>
</div>
<fieldset><legend><img src="/img/icons/delete.png" alt="" style="vertical-align:middle; line-height:16px; height:16px; padding-right:5px;" /> All Removal Links</legend>
    Do not share the links below. You can use them to delete the photos you have uploaded.<br />
<textarea onclick="this.select()" style="width:600px; height:200px;"></textarea>
</fieldset>
<!-- Google Code for Imagebam Uploaded Image Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 1068053810;
var google_conversion_language = "en_US";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "6tqpCPa-chCy6qT9Aw";
var google_conversion_value = 0;
/* ]]> */
</script>
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1068053810/?label=6tqpCPa-chCy6qT9Aw&amp;guid=ON&amp;script=0" />
</div>
</noscript>
</div>
<div class="footer">
<a class="footera" href="http://www.imagebam.com/">ImageBam</a> | <a class="footera" href="/remote-upload-widget">Remote Upload Widget</a> | <a class="footera" href="http://www.imagebam.com/screengrab_upload_firefox_extension">screengrab tool</a> | <a class="footera" href="http://www.imagebam.com/terms-of-service">terms of service</a> | <a class="footera" href="http://www.imagebam.com/frequently-asked-questions">help</a> | <a class="footera" href="http://support.imagebam.com" target="_blank">support forums</a> | <a class="footera" href="http://code.google.com/p/imagebam-api/">API for developers</a> | <a class="footera" href="http://www.imagebam.com/report-abuse">report abuse</a>
<div style="height:35px; overflow:hidden;">
<div id="google_translate_element" style="margin-top:9px;"></div><script type="text/javascript">
function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: 'en'
  }, 'google_translate_element');
}
</script><script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit" type="text/javascript"></script>
</div>
<div style="text-align:center; color:#999; margin-top:10px;">
<table style="margin:auto;"><tr><td><img src="http://1.imagebam.com/static/img/tux.png" alt="tux" /></td><td>Powered by dedicated Linux servers. Flixya Entertainment, LLC &copy; 2010</td></tr></table>
</div>
</div>
</div>
<div id="updater_index"></div>
<script type="text/javascript">
</script>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2424497-2";
urchinTracker();
</script>
</body>
</html>

快速、免费的图像托管-ImageBam

/* */ 在后台处理的缩略图可能无法立即加载。
突然 BB代码
HTML代码
所有删除链接 不要共享下面的链接。您可以使用它们删除已上载的照片。
/* */ | | | | | | | 函数googleTranslateElementInit(){ 新的google.translate.TranslateElement({ 页面语言:“en” }“谷歌翻译元素”); } 由专用的Linux服务器提供动力。Flixya娱乐有限责任公司&复印件;2010 _uacct=“UA-24497-2”; 海胆追踪者();
通常,上传后的页面会显示图像链接等。 但我认为这是一个动态的过程,因为当我得到这个页面时,链接还没有准备好


我错过什么了吗?因为即使您不填写表单上的输入,如果您提交()表单,它也会在上载页面后重定向到该页面。

使用select_control()和nr=0来选择第一个文件。

您可以尝试使用select_control和nr=0来选择第一个文件?这看起来像是dup,看起来像是dup。但没有解决办法@Lennart,非常感谢你的回答,很有效!好的,我不确定它是否会起作用,我还没有用过nr=我自己。我想我可以完美地将我的文件输入到输入中(这里),事实上它也显示了我的文件名,比如;但我认为真正的问题是关于多部分表单的东西,因为这是一个上传过程,我不认为它会因为我把文件放在那里而上传。。我记得在一些网站上,有一些文本在状态栏中显示像“%nn done”这样的过程。我只是结巴了。。我如何才能让我的代码真正“发送”数据?@user1148029:这是另一个问题。:-)我不记得了。其他人可能知道,所以你应该提出一个新问题。
a["file[]"]=dosya
Traceback (most recent call last):
  File "<pyshell#46>", line 1, in <module>
    a["file[]"]=dosya
  File "build\bdist.win32\egg\mechanize\_form.py", line 2780, in __setitem__
    control = self.find_control(name)
  File "build\bdist.win32\egg\mechanize\_form.py", line 3101, in find_control
    return self._find_control(name, type, kind, id, label, predicate, nr)
  File "build\bdist.win32\egg\mechanize\_form.py", line 3183, in _find_control
    raise AmbiguityError("more than one control matching "+description)
AmbiguityError: more than one control matching name 'file[]'
<?xml version='1.0' encoding='utf-8'?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://opengraphprotocol.org/schema/" xmlns:fb="http://developers.facebook.com/schema/" xmlns:dc="http://purl.org/dc/elements/1.1/" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="author" content="ImageBam.com" />
<meta name="description" content="Free Image Hosting and photo sharing. Create an online album with bulk upload tools and share with family and friends." />
<meta name="keywords" content="image hosting, free image hosting, photo sharing, upload photo, free photo gallery, photo host, image gallery" />
<meta name="robots" content="follow" />
<meta name="revisit-after" content="1 days" />
<meta property="fb:admins" content="3433880" />
<link rel="stylesheet" href="http://www.imagebam.com/style.css" type="text/css" />
<link rel="shortcut icon" href="http://www.imagebam.com/favicon.ico" />
<title>Fast, Free Image Hosting - ImageBam</title>
<script type="text/javascript" src="http://www.imagebam.com/JS/imagebam.js"></script>
<script type="text/javascript" src="http://www.imagebam.com/JS/pt.js"></script>
</head>
<body>
<!-- IMAGEBAM HEADER -->
<div class="scrollme">
<div class="abody">
<!-- everything -->
<div class="banner cursor" style="float:left;" onclick='top.location="http://www.imagebam.com"'></div>
<div style="float:right; text-align:right; border:0px solid #f2f2f2; border-top:none; padding-top: 5px; padding-left:3px; padding-right:10px;">
</div>
<div style="clear:left;"></div>
<div class="dtab">
<ul>
<li class="inactive"><a href="/">Multi-Upload</a></li>
<li class="inactive"><a href="/zip-upload">Zip-Upload</a></li>
<li class="inactive"><a href="/basic-upload">Basic Upload</a></li>
<li class="inactive"><a href="/learn-more">Learn More</a></li>
<li class="inactive"><a href="/frequently-asked-questions">FAQ</a></li>
<li class="inactive"><a href="/register">Register</a></li>
<li class="inactive"><a href="/login">Login</a></li>
<li class="inactive"><a href="/premium">Premium</a></li>
</ul>
</div><br />
<!-- Google Code for Imagebam Uploaded Image Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
function img404(ID,fsrc){
    document.getElementById('thumb_404_info').style.display="block";
    document.getElementById("img_"+ID).style.display = "none";
    document.getElementById("alt_"+ID).style.display = "inline";
    setTimeout("reloadImg("+ID+",'"+fsrc+"')", 500);
}

function reloadImg(ID,fsrc){
    mrand = Math.random();
    document.getElementById("img_"+ID).style.display = "inline";
    document.getElementById("alt_"+ID).style.display = "none";
    document.getElementById("img_"+ID).src = fsrc+"?"+mrand;
}


/* ]]> */
</script>
<div class="box_wait" style="text-align:center; display:none;" id="thumb_404_info">Thumbnails that are being processed in the background might not load right away.<br /></div>
<div style="text-align:center; margin-bottom:5px;">
<a href="http://videobam.com" target="_blank" style="font-weight:bold; font-size:22px; text-align:center; color:#0174B3;"><b>NEW!</b> VideoBam.com (HD Video Hosting)</a>
</div>
<fieldset><legend><img src="/img/icons/photos.png" alt="" style="vertical-align:middle; line-height:16px; height:16px; padding-right:5px;" /> All at Once</legend>
<table style="width:100%;"><tr>
<td>
<b>BB-Code</b><br />
<textarea onclick="this.select();" style="width:300px; height:200px;"></textarea>
</td>
<td>
<b>HTML-Code</b><br />
<textarea onclick="this.select();" style="width:300px; height:200px;"></textarea>
</td>
</tr>
</table>
</fieldset>
<!--
<fieldset><legend style='color:green;'><img src='/img/icons/new.png' alt='' style='vertical-align:middle; line-height:16px; height:16px; padding-right:5px;'> NEW! ImageBam Remote Upload Widget</legend>
<b>Webmasters / Mods!</b><br> Allow your users to upload images to ImageBam <b>without leaving your website or forum!</b><br> Add our new <a href="/remote-upload-widget" target="_blank">ImageBam Remote Upload Widget</a> to you website!<br>
Please spread the word! Thank you!
</fieldset>
-->
<div style="text-align:center; margin-bottom:5px;">
<a href="http://videobam.com" target="_blank" style="font-weight:bold; font-size:22px; text-align:center; color:#0174B3;"><b>NEW!</b> VideoBam.com (HD Video Hosting)</a>
</div>
<fieldset><legend><img src="/img/icons/delete.png" alt="" style="vertical-align:middle; line-height:16px; height:16px; padding-right:5px;" /> All Removal Links</legend>
    Do not share the links below. You can use them to delete the photos you have uploaded.<br />
<textarea onclick="this.select()" style="width:600px; height:200px;"></textarea>
</fieldset>
<!-- Google Code for Imagebam Uploaded Image Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 1068053810;
var google_conversion_language = "en_US";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "6tqpCPa-chCy6qT9Aw";
var google_conversion_value = 0;
/* ]]> */
</script>
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1068053810/?label=6tqpCPa-chCy6qT9Aw&amp;guid=ON&amp;script=0" />
</div>
</noscript>
</div>
<div class="footer">
<a class="footera" href="http://www.imagebam.com/">ImageBam</a> | <a class="footera" href="/remote-upload-widget">Remote Upload Widget</a> | <a class="footera" href="http://www.imagebam.com/screengrab_upload_firefox_extension">screengrab tool</a> | <a class="footera" href="http://www.imagebam.com/terms-of-service">terms of service</a> | <a class="footera" href="http://www.imagebam.com/frequently-asked-questions">help</a> | <a class="footera" href="http://support.imagebam.com" target="_blank">support forums</a> | <a class="footera" href="http://code.google.com/p/imagebam-api/">API for developers</a> | <a class="footera" href="http://www.imagebam.com/report-abuse">report abuse</a>
<div style="height:35px; overflow:hidden;">
<div id="google_translate_element" style="margin-top:9px;"></div><script type="text/javascript">
function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: 'en'
  }, 'google_translate_element');
}
</script><script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit" type="text/javascript"></script>
</div>
<div style="text-align:center; color:#999; margin-top:10px;">
<table style="margin:auto;"><tr><td><img src="http://1.imagebam.com/static/img/tux.png" alt="tux" /></td><td>Powered by dedicated Linux servers. Flixya Entertainment, LLC &copy; 2010</td></tr></table>
</div>
</div>
</div>
<div id="updater_index"></div>
<script type="text/javascript">
</script>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2424497-2";
urchinTracker();
</script>
</body>
</html>