我正在尝试解析包含汽车属性的网站(154种属性).我有一个巨大的列表(名称是 liste_test),包含280.000二手车公告网址.
def araba_cekici(liste_test,headers,engine):
for link in liste_test:
try:
page = requests.get(link, headers=headers)
.....
.....
Run Code Online (Sandbox Code Playgroud)
当我开始这样的代码时:
araba_cekici(liste_test,headers,engine)
Run Code Online (Sandbox Code Playgroud)
它起作用并获得结果.但大约在1小时内,我只能获得1500个URL的属性.它非常慢,我必须使用多处理.
我在这里找到了一个带有多处理的结果.然后我申请了我的代码,但不幸的是,它没有用.
import numpy as np
import multiprocessing as multi
def chunks(n, page_list):
"""Splits the list into n chunks"""
return np.array_split(page_list,n)
cpus = multi.cpu_count()
workers = []
page_bins = chunks(cpus, liste_test)
for cpu in range(cpus):
sys.stdout.write("CPU " + str(cpu) + "\n")
# Process that will send corresponding list of pages
# to the function perform_extraction
worker = …Run Code Online (Sandbox Code Playgroud)