chatgpt derki :
import requests
import concurrent.futures
class YourClass:
def getdata(self, category):
sayfasayi = False
dusdata = []
urunler = []
x = 1
def process_page(page):
params = {
'page': str(page),
}
while True:
try:
response = requests.get("https://www.test.com", params=params)
if response.status_code == 200:
print(page)
html = response.json()
break
else:
raise Exception(f"Status: {response.status_code}")
except Exception as e:
print(f"An error occurred: {e}")
for r in html['products']:
isim = r['name']
url = BASE_URL + r["url"]
urunler.append([isim, url])
try:
# Burada json işlemi var
pass
except Exception as e:
print(f"An error occurred: {e}")
with concurrent.futures.ThreadPoolExecutor() as executor:
while sayfasayi == False:
futures = [executor.submit(process_page, x)]
x += 1
if x > int(category["sayfasayisi"]):
sayfasayi = True
self.urunsayisi += len(urunler)
urunler.clear()
dusdata.clear()concurrent.futures kullanmak için detaylı makale
https://zetcode.com/python/concurrent-http-requests/