I am writing a program for scraping data from multiple urls using multiprocessing. Here I stored all the URLs in the bonds_url list. It is working and I am getting output but the problem here is that output is in random orders. I want scraped data to be in the same order as the order of URLs in bonds_url. Is there any solution for that?
from requests_html import HTMLSession
import constants
bonds_url =[]
from multiprocessing import Pool
def f(url):
session = HTMLSession()
response = session.get(url)
try:
data = [i.text.strip() for i in response.html.find(".value") ]
bonds_values.append(float(data[0]))
print(data[0])
except:
data = [i.text.strip() for i in response.html.find("div>span[data-reactid='31']")]
bonds_values.append(float(data[0]))
print(data[0])
if __name__ == '__main__':
with Pool(len(bonds_url)) as p:
p.map(f, bonds_url)