【问题标题】:Loop a short python script that parses data from a json file循环一个从 json 文件解析数据的短 python 脚本
【发布时间】:2020-05-29 16:22:05
【问题描述】:

我希望标题有意义,英语不是我的第一语言,有点不知道我是否写对了.. 基本上我有一个用于网络钓鱼网站的 python 脚本,用随机数据向它们发送垃圾邮件。 我有一个 .py 文件和一个 .json 文件。

app.py:

import requests
import os
import random
import string
import json

chars = string.ascii_letters + string.digits + '!@#$%^&*()'
random.seed = (os.urandom(1024))

url = 'site/file.php'

names = json.loads(open('names.json').read())

for name in names:
    name_extra = ''.join(random.choice(string.digits))

    username = name.lower() + name_extra + '@yahoo.com'
    password = ''.join(random.choice(chars) for i in range(12))

    requests.post(url, allow_redirects=False, data={
        'login': username,
        'pass': password
    })

    print ('sending username %s and password %s' % (username, password))

json 有几个随机名称:

[
"Liam",
"Noah",
"William"
]

在我的 names.json 中,我有大约 40 个随机名称,每次我启动程序时,它都会遍历所有 40 个名称,然后它就会关闭.. 有没有办法让我无限循环这些名字?并让程序 24/7 运行?

【问题讨论】:

    标签: python json python-3.x parsing python-requests


    【解决方案1】:

    如果你真的希望它永远运行(或直到你结束它),你可以使用

    while(True):
        print("This will go forever")
    

    目前尚不清楚您希望永远运行哪个部分,但在您的情况下,这看起来像

    while(True):
        for name in names:
            name_extra = ''.join(random.choice(string.digits))
    
            username = name.lower() + name_extra + '@yahoo.com'
            password = ''.join(random.choice(chars) for i in range(12))
    
            requests.post(url, allow_redirects=False, data={
                'login': username,
                'pass': password
            })
    
            print ('sending username %s and password %s' % (username, password))
    

    【讨论】:

      猜你喜欢
      • 2018-07-18
      • 2016-08-17
      • 2021-10-17
      • 1970-01-01
      • 2016-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多