I am learning scraping with python. The problem with the given below code is that it does not show or save the data in correct order. As I am doing it with the help of threading.
Whenever I build a scraper, I face the same problem. Please tell me the way to fix it.
import requests
from bs4 import BeautifulSoup as bs
import threading
def scrape(page):
baseUrl = "http://quotes.toscrape.com/page/"
html = requests.get(baseUrl+str(page))
soup = bs(html.text, "lxml")
author = soup.find_all("small", class_="author")
for auth in author:
print(auth.text)
print("The page number is "+ str(page)) #printing the page number
ml = [x for x in range(2, 12)]
threadList = []
for u in ml:
t = threading.Thread(target=scrape, args=(u,))
t.start()
threadList.append(t)
for b in threadList:
b.join()
question from:
https://stackoverflow.com/questions/65945047/how-do-i-get-the-scraped-data-in-correct-order-with-threading 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…