如何加快爬蟲(爬取Github API的速度)

2021-09-11 05:30:51 字數 2634 閱讀 7181

爬蟲出現問題,request失敗後,乙個專案的都會break,需要再手動爬取

解決方案:

1 logging module

2 改變while,實現佇列:這頁爬完了 i+1 加到佇列中 ,爬取失敗後重新加入佇列,這樣就不用每次再開啟

參考:3 爬取失敗的放到乙個list,爬取完成後,刪除該list裡面內容

(async_example.results)之前科研需要爬取github api的資料,少量的直接request即可,遇到大量的資料怎麼辦,太慢了!

三種解決方案:

主要是用到這個

from multiprocessing.dummy import pool as threadpool
參考文章:

python多執行緒爬蟲例項

講解文章:

主要用到這兩個

import asyncio

import aiohttp

參考文章:

爬蟲速度太慢用非同步協程提速

講解文章:

爬蟲爬取bilibili

1.根據url傳送請求給伺服器,獲取html文字 2.解析html文字,把需要的資料挑出來 3.從html中解析出超連結,繼續爬取其中的頁面 爬蟲的協議b站的爬蟲協議 尾巴加上 robots.txt 獲取相應的api 控制抓取的頻率 import requests url 發起網路請求 respon...

python提高爬蟲速度 如何提高爬蟲爬取的速度?

寫了個簡單的協程爬蟲爬取b站使用者資訊,如下 import requests import re import json import datetime import asyncio def get info uid url info 基本資訊 uid str uid return loop.run...

Python 爬蟲爬取網頁

工具 python 2.7 import urllib import urllib2 defgetpage url 爬去網頁的方法 request urllib.request url 訪問網頁 reponse urllib2.urlopen request 返回網頁 return response...