当前位置: 首页 > 知识库问答 >
问题:

Python保存验证码图像从url?错误401[重复]

蒋俊人
2023-03-14

我无法将验证码保存为png。这是到目前为止我的代码

import requests
url_login = "https://www.hackthis.co.uk/?login"
r_login = requests.post(url_login, {'username': 'darkcyber', 'password': 'secr3tp4s5'})
print r_login.status_code
if "Invalid login details" in r_login.text:
        print "Failed to login"
else:
        print "Login success"
url_captcha = "https://www.hackthis.co.uk/levels/extras/captcha1.php"
r_captcha = requests.get(url_captcha)
#print r_captcha.status_code << 401 instead 200
#whats next?

共有1个答案

夏何平
2023-03-14

您需要下载图像并保存到本地为新文件。

以下是示例代码:

import requests

r = requests.get('http://url.com/captcha.php')

f = open('yourcaptcha.png', 'wb')
f.write(r.content)
f.close()

评论后更新:

import requests
url_login = "https://www.hackthis.co.uk/?login"

r_login = requests.post(url_login, {'username': 'darkcyber', 'password': 'secr3tp4s5'})

if "Invalid login details" in r_login.text:
        print "Failed to login"
else:
        print "Login success"

url_captcha = "https://www.hackthis.co.uk/levels/extras/captcha1.php"
r_captcha = requests.get(url_captcha, cookies=r_login.history[0].cookies)

print r_captcha.status_code

f = open('yourcaptcha.png', 'wb')
f.write(r_captcha.content)
f.close()
 类似资料:
  • 问题内容: 我在使用python通过urllib2请求或urllib.urlretrieve从url保存图像时遇到问题。那是图像的URL是有效的。我可以使用资源管理器手动下载它。但是,当我使用python下载图像时,无法打开该文件。我使用Mac OS预览来查看图像。谢谢! 更新: 代码如下 我要下载的图像URL是 http://site.meishij.net/r/58/25/3568808/a3

  • 问题内容: 我需要将图像从PHP URL保存到PC。假设我有一个页面,其中仅包含一个“花”图像,仅此而已。如何使用新名称(使用PHP)从URL中保存该图像? 问题答案: 如果您设置为: 其他使用cURL:

  • 问题内容: 我需要使用CURL从URL保存图像并将其保存到服务器上的文件夹中。我一直在努力与这段代码无济于事。理想情况下,我想获取图像并将其另存为“ photo1”或其他内容。帮帮我! 问题答案: 尝试这个: 并确保在php.ini中启用allow_url_fopen

  • 问题内容: 非常奇怪的错误。我使用的是http://developers.facebook.com/docs/authentication/。所以我创建了对fb的请求并传递redirect_uri。我在本地主机上使用测试站点。所以如果我通过 redirect_uri = http://localhost/test_blog/index.php 它工作正常,但如果我通过 redirect_uri =

  • 我正在为我的azure无状态服务fabric应用程序从密钥存储库中获取机密值,并在100s密钥存储库机密中仅有2个密钥存储库机密获得401个依赖项错误(如果我通过connected application insight检查的话)。下面给出的是通过应用程序洞察显示的依赖错误的截图,其中一个密钥存储库的秘密。 这里请求路径是https://mykeyvaultname.vault.azure.net

  • 我尝试此操作时出现以下错误 警告:fopen(/var/www/ajaxForm/loading.gif):无法打开流:在/var/www/curlmimage中没有这样的文件或目录。php第5行警告:fwrite()希望参数1是资源,布尔值在/var/www/curlmimage中给出。php第6行警告:fclose()希望参数1是资源,布尔值在/var/www/curlmimage中给出。ph