0
time
モジュールを使用して、5秒以上かかると次の繰り返しにスキップするにはどうすればよいですか?具体的には、How would I stop a while loop after n amount of time?からfor
ループを使用してソリューションを実装する正しい方法は何ですか?forループのタイムモジュールを使用してリスト処理の遅延を防ぐ方法
import requests
from bs4 import BeautifulSoup
for n in random_list:
url = all_raw_urls[n]
try:
req = requests.get(url)
data = req.text
soup = BeautifulSoup(data, 'html.parser')
tags = soup.find_all('img')
tags = list(set(tags))
if len(tags) < 15 or len(tags) > 50:
print(str(image_count) + ': leave' + ' : images: ' + str(len(tags)))
else:
print(str(image_count) + ': keep' ' : images: ' + str(len(tags)))
image_urls.append(url)
except:
print('request error')
image_count += 1
ありがとう! – McLeodx