@alexto13

Почему плохо отрабатывет скрипт при multiprocessing?

Здравствуйте,помогите пожалуйста разобраться почему второй код при мультипроцессинге код не заполняет все 40 ячеек в exel ,как первый и как можно с этим что-то сделать?Заранее благодарен за ответы.
Первый скрипт:
import time
from concurrent.futures import ThreadPoolExecutor

import pandas as pd
import requests
from bs4 import BeautifulSoup
import multiprocessing as mp
url = "https://supl.biz/abrazivnyij-instrument-category414/"
HEADERS = {'User-Agent': 'Mozilla/5.0'}

all = []


def parse(all):
    recponse = requests.get(url, headers=HEADERS)
    soup = BeautifulSoup(recponse.text, 'lxml')
    countrys = soup.find_all('div', class_='a_0C-R-igw')
    for country in countrys:
        item = {}

        item['Title'] = country.find('a', class_='a_1f5wjnCB').text
        item['Firma'] = country.find('a', class_='c_3icLR39w a_1f5wjnCB').text
        item['Price'] = country.find('span', class_='a_gT7Tdbnz').text
        # print(item)
        all.append(item)
        print(f'All:{all}')

 parse(all)

Второй скрипт:
import pandas as pd
import requests
from bs4 import BeautifulSoup
import multiprocessing as mp
url = "https://supl.biz/abrazivnyij-instrument-category414/"
HEADERS = {'User-Agent': 'Mozilla/5.0'}

all = []


def parse(all):
    recponse = requests.get(url, headers=HEADERS)
    soup = BeautifulSoup(recponse.text, 'lxml')
    countrys = soup.find_all('div', class_='a_0C-R-igw')
    for country in countrys:
        item = {}

        item['Title'] = country.find('a', class_='a_1f5wjnCB').text
        item['Firma'] = country.find('a', class_='c_3icLR39w a_1f5wjnCB').text
        item['Price'] = country.find('span', class_='a_gT7Tdbnz').text
        # print(item)
        all.append(item)
        print(f'All:{all}')
       





if __name__ == '__main__':
    parse(all)

    with mp.Pool(6) as pool:
        mp_result1 = pool.map(parse, [all])  # <--this line right here

        for item in mp_result1:
            print(mp_result1)

            print(item)

            data = pd.DataFrame(item)
            data.to_excel('how.xlsx', index=False)

Отработка первого:
63be790a784f2600255544.png

Отработка второго:
63be7b38b5fa7544602415.png
  • Вопрос задан
  • 76 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы