0

Example I have this code


with open("palavras.txt","r",encoding='ISO-8859-1') as f:
    for line in f:
        palavras.append(line)

sinonimos=[]

nr_palavras = len(palavras)

palavras_com_sinonimos=[]



def fazer():
    for i in range(0,nr_palavras):
        URL = 'https://www.sinonimos.com.br/'+palavras[i].replace('\n','')
        texto_html = requests.get(URL)
        if texto_html.status_code==404:
            print(" A Palavra {} não existe".format(palavras[i].replace('\n','')))
        else:
            palavras_com_sinonimos.append(palavras[i].replace('\n',''))

Theres more than 2 million words in palavras.txt that will take alot time, theres any thing I can do to run it faster ?

byViruZz
  • 1
  • 2
  • By running your code asynchronously: each thread will be downloading its own webpage. Look up `concurrent.futures` and "asynchronous (or concurrent) programming" in general – ForceBru Dec 21 '19 at 16:20
  • Take a read here https://stackoverflow.com/q/30294146/7548672 –  Dec 21 '19 at 16:27

0 Answers0