<p>我在写剧本,看这里:</p>
<pre><code>from pysnap import Snapchat
import time
usnlist = raw_input('Enter file name: ')
s = Snapchat()
def filter(username, password):
s.login(username, password)
with open (usnlist, 'r') as file:
for line in file:
ok = False
while not ok:
try:
resp = s.add_friend(line.rstrip("\n"))
if 'object' in resp.keys():
# 'object' is contained within resp as a key
if resp['object']['type']:
# type is 1
with open ('private.txt', 'a') as f: f.write(resp['object']['name']+"\n")
print line.rstrip("\n") + "'s",
print "privacy settings are set to: FRIENDS"
else:
# type is 0
with open ('n-private.txt', 'a') as f: f.write(resp['object']['name']+"\n")
print line.rstrip("\n") + "'s",
print "privacy settings are set to: EVERYONE"
s.delete_friend(line)
else:
# no object in resp, so it's an invalid username
print line.rstrip("\n") + " is not a valid username"
ok = True
except:
time.sleep(5)
print "SNAPCHAT SERVER OVERLOAD - HOLD ON."
username = raw_input('Enter username: ')
password = raw_input('Enter password: ')
filter(username, password)
</code></pre>
<hr/>
<p>我现在想要的是能够输入一个值,我们称之为<code>n</code>
当我输入<code>n</code>时,bot只会刮取每一行<code>n</code>。你知道吗</p>
<p>例如。<code>N = 2</code>。
机器人现在只从列表中抓取和输入每秒钟一个用户名。你知道吗</p>
<p>我想到了一些东西,比如将[0::2]添加到:<code>resp = s.add_friend(line.rstrip("\n"))</code>
导致:<code>resp = s.add_friend(line[0::2].rstrip("\n"))</code></p>
<p>但这不起作用,bot直接转到<code>print "SNAPCHAT SERVER OVERLOAD - HOLD ON."</code>
不查名字。你知道吗</p>
<p>我的想法是:</p>
<pre><code>http://stackoverflow.com/questions/18155682/gathering-every-other-string-from-list-line-from-file
</code></pre>
<p>但所提供的信息还不足以让这一切顺利进行。
<strong>我使用python 2.7.8</p>
<p>我希望有一种方法可以告诉python:“获取文件中的每一行”
因为这基本上就是我要找的。你知道吗</p>
太好了!你知道吗</p>