0
많은 수의 URL에서 웹 스크래핑을 사용하려고하는데 속도를 높이기 위해 멀티 프로세싱을 적용했지만 왜 속도가 향상되지 않는지 모릅니다. 여기에 내 코드의 일부입니다웹 스크래핑 다중 처리가 작동하지 않습니다.
def scrap(url,output_path):
page = urlopen(URL)
soup = BeautifulSoup(page, 'html.parser')
item_text = soup.select('#scatter6001 script')[0].text
table = soup.find_all('table',{'class':'noborder dark'})
df1 = pd.read_html(str(table),header = 0)
df1 = pd.DataFrame(df1[0])
...
# function for scraping the data from url
rootPath = '...'
urlp1 = "https://www.proteinatlas.org/"
try:
df1 = pd.read_csv(rootPath + "cancer_list1_2(1).csv", header=0);
except Exception as e:
print("File " + f + " doesn't exist")
print(str(e))
sys.exit()
cancer_list = df1.as_matrix().tolist()
URLs = []
for cancer in cancer_list:
urlp2 = "/pathology/tissue/" + cancer[1]
f = cancer[0]
try:
df1 = pd.read_csv(rootPath + f + ".csv", header=0);
except Exception as e:
print("File " + f + " doesn't exist")
print(str(e))
sys.exit()
...
# list of URLs
if __name__ == '__main__':
pool = multiprocessing.Pool(processes=6)
records = p.map(scrap(url,output_path))
p.terminate()
p.join()
웹 스크래핑 사용하여 멀티 프로세싱을 빠르게하는 방법을 확실하지.
공유를 해주셔서 감사하지만 코드를 수정 한 후에도 속도가 향상되지 않습니다. '경우 __name__ == '__main__' 풀 = multiprocessing.Pool (공정 = 6) FUNC = 람다 URL : 스크랩 (URL, output_path) p.map (FUNC 사진, URL) p.terminate() P .join()' –
실례 합니다만 파이썬과 멀티 프로세싱을 처음 접했습니다. –
테스트 코드에서 멀티 프로세싱을 성공적으로 사용 했습니까? – wkzhu