M
M
Morrdor2020-08-11 16:23:46
Python
Morrdor, 2020-08-11 16:23:46

How to organize multithreading in this Python example?

import xml.etree.ElementTree as et
import requests
from bs4 import BeautifulSoup
import threading

iterar = input ('How many domains you want to check: ')
domainlist = []
try:
   iterar = int(iterar)
except ValueError:
    print('incorrect value')
if iterar <= 0:
    print('Please write a count of domains you want to be cheked')
i=0
while i<iterar:
    i=i+1
    allDomain = input(f'Enter Domain N{i}:')
    domainlist.append(allDomain)
while domainlist:
   domain = domainlist.pop(0)
   result = requests.get(f'http://data.alexa.com/data?cli=20&dat=snbamz&url={domain}')
   data_string = result.text
   root = et.fromstring(data_string) 
   rank = [item.attrib.get('RANK') for item in root.findall('.//REACH')]
   print(f"\nDomain: \'{domain}\'")
   print(f"Alexa Rank: {rank}\n".replace("[", "").replace("]", ''))
input()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-08-11
@bacon

Learn to find solutions yourself, there is a well-known article that is already a lot of years old, google without problems https://chriskiehl.com/article/parallelism-in-one-line even seemed to have a translation on Habré

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question