beautifulsoup를 사용하여 웹 스크래핑을 수행하고 구문 분석 된 데이터를 CSV 파일에 성공적으로 저장했지만 다중 처리를 사용하기 위해 프로세스의 속도를 높이고 싶습니다. 그러나 스크립트에서 다중 처리를 적용한 후에는 아무런 차이가 없습니다. 여기파이썬 웹 스크랩에서 돌연변이 처리가 작동하지 않음
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()
# [["bcla_gene","beast+cancer"], ...]
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
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])
Number = soup.find('th',text = "Number of samples").find_next_sibling("td").text
...
#function of scraping
if __name__ == "__main__":
Parallel(n_jobs=-1)(scrap(url,output_path) for url in URLs)
그냥 코드를 업데이트 내 코드와 문제는 이제 CPU 사용률은 처음에 100 %에 도달 할 수 있지만, 곧 1 %로 떨어질 것입니다. 나는 그것에 대해 아주 혼란스러워합니다.
하나의 스레드 만 시작하고 다중 프로세스는 시작하지 않습니다. – georgexsh