我有一个带有用户名和密码的文本文件.文本文件的格式如下:
username1:password1
username2:password2
username3:password3
Run Code Online (Sandbox Code Playgroud)
我想抓住第一行,将其拆分为"username1"和"password1",然后发布到:
br.form['login'] = 'username1'
br.form['passwd'] = 'password1'
Run Code Online (Sandbox Code Playgroud)
之后,我希望它重复并转移到username2:password2.
如何才能做到这一点?
假设:您的用户名或密码中没有字符.
with open('myfile.txt') as f:
credentials = [x.strip().split(':', 1) for x in f]
for username, password in credentials:
# your code here
Run Code Online (Sandbox Code Playgroud)
小智 5
1)逐行读取文件 http://docs.python.org/tutorial/inputoutput.html
2)拆分行(字符串) http://docs.python.org/library/string.html
3)发布信息 http://docs.python.org/library/urllib.html
使用谷歌帮助找出每一步.