我正在尝试编写一个python脚本来自动renew fastssh account。在续订页面上,有一个如下结构的验证码:
<label>
<img src='https://fastssh.com/images/temp/blablablabla1.jpg' >
X
<img src='https://fastssh.com/images/temp/blablablabla2.jpg' >
=
</label>
<input type="text" name="CaptchaPass" id="captcha" required/>
所以我需要从两个jpg
中确定两个数,然后做算术。为了自动化这个过程,我尝试用以下代码获取jpg
:
import requests, sys
from bs4 import BeautifulSoup
url = 'https://www.fastssh.com/page/renew-ssh-account'
s = requests.session()
text = s.get(url).text
soup = BeautifulSoup(text)
options = soup.find_all('option')
found = False
for option in options:
if 'fr.serverip.co' in ''.join(option.contents):
serverid = option['value']
found = True
break
if not found:
sys.exit('server not found.')
captcha = soup.find(id='captcha')
imgTag2 = captcha.find_previous('img')
img2 = s.get(imgTag2['src'], stream=True)
with open('num2.jpg', 'wb') as out:
for block in img2.iter_content(1024):
if not block:
break
out.write(block)
然而,最后写入磁盘的num2.jpg
实际上是一个html
文件!你知道吗
我还发现,如果我使用我的chrome浏览器来加载renew page,手动将jpg
url从html源代码复制并粘贴到一个新的选项卡,然后按enter键,它实际上会将我重定向到主页,我相信这就是我在num2.jpg
上面得到的。你知道吗
我想这可能和饼干有关?但是requests
包中的会话不应该处理所有必需的cookie吗?你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐