1
我正在使用蟒蛇 - Python 3.5.2如何提高此python請求會話的速度?
我有一個280,000個網址的列表。 我正在抓取數據並試圖追蹤url-to-data。
我已經提出了約30K個請求。我每秒平均請求1次。
response_df = pd.DataFrame()
# create the session
with requests.Session() as s:
# loop through the list of urls
for url in url_list:
# call the resource
resp = s.get(url)
# check the response
if resp.status_code == requests.codes.ok:
# create a new dataframe with the response
ftest = json_normalize(resp.json())
ftest['url'] = url
response_df = response_df.append(ftest, ignore_index=True)
else:
print("Something went wrong! Hide your wife! Hide the kids!")
response_df.to_csv(results_csv)
請同時適當縮進代碼 –
,考慮paralellizing代碼。 –
另外,請考慮預先分配輸出DF。 –