PDF અથવા છબી પ્રોક્સી દ્વારા સફળતાપૂર્વક આવી શકે છે અને પછી બેન શોધમાં નિષ્ફળ જાય છે. Scrapyનું મૂળ Response બોડી બાઇટ્સ બતાવે છે, પરંતુ તેની text ગુણધર્મ “Response content isn't text.” ભૂલ ઉઠાવે છે.

જો સ્થાપિત scrapy-proxy-pool નીતિ શરત વિના response.text શોધે છે, તો તે નીતિને પ્રકાર-જાગૃત આવૃત્તિથી બદલો:

from scrapy.http import TextResponse
from scrapy_proxy_pool.policy import BanDetectionPolicy

class BinaryAwarePolicy(BanDetectionPolicy):
    def response_is_ban(self, request, response):
        if isinstance(response, TextResponse):
            if self.BANNED_PATTERN.search(response.text):
                return True
        if response.status not in self.NOT_BAN_STATUSES:
            return True
        return response.status == 200 and not response.body

પેકેજની એક્સ્ટેન્શન સેટિંગ દ્વારા તેને પસંદ કરો:

PROXY_POOL_BAN_POLICY = "myproject.policy.BinaryAwarePolicy"

આ નીતિના સ્થિતિ અને ખાલી-બોડી નિયમો જાળવે છે અને લખાણ શોધને ફક્ત તેને સમર્થન આપતા પ્રતિભાવો સુધી મર્યાદિત કરે છે. વારસામાં મળેલી અપવાદ નીતિ પણ ઉપલબ્ધ રહે છે.

બાકીના નિયમોને પણ એપ્લિકેશન માટે સમીક્ષા કરો: ઇરાદાપૂર્વક ખાલી 200 પ્રતિભાવ અથવા સામાન્ય લક્ષ્ય ભૂલ હંમેશા ખરાબ પ્રોક્સીનો પુરાવો નથી. મિડલવેર સક્રિય રાખો અને નિષ્ફળતાનું કારણ બનેલું વર્ગીકરણ બદલો, બાઈનરી ડાઉનલોડ માટે બધી બેન શોધ બંધ કરવાને બદલે.

સંબંધિત લેખો