Доступ к CloudFlare запрещен при запуске скрипта загрузки и анализа

Я занимаюсь юридической проблемой и создал сценарий, чтобы мне не приходилось искать сайт вручную.

Автор сценария:

import sys, urllib

servno = 2000
servernomax = 2676
alldat = ""

while True:
    newdat = ""
    url = "http://coc-servers.com/servers/"+str(servno)
    wp = str(urllib.urlopen(url).read())
    print wp
    ind1 = wp.find('"IP: "')
    if ind1 != -1:
        ind1 += 7
        ind2 = wp.find('http',ind1)
        ind3 = wp.find('"',ind2)
        IPurl = wp[ind2:ind3]
        newdat += IPurl
    ind4 = wp.find("<th>Webiste</th>")
    if ind4 != -1:
        ind4 +=22
        ind5 = wp.find('http',ind4)
        ind6 = wp.find('"',ind5)
        Website = wp[ind5:ind6]
        newdat += ", "
        newdat += Website
    alldat += newdat
    servno +=1
    #print ind1, ind4
    if servno > 2676: break

print alldat
sys.exit()

Ошибка свободна, однако некоторые значения нуждаются в настройке.

Выход?

<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js ie6 oldie" lang="en-US"> <![endif]-->
<!--[if IE 7]>    <html class="no-js ie7 oldie" lang="en-US"> <![endif]-->
<!--[if IE 8]>    <html class="no-js ie8 oldie" lang="en-US"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en-US"> <!--<![endif]-->
<head>
<title>Access denied | coc-servers.com used CloudFlare to restrict access</title>
<meta charset="UTF-8" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
<meta name="robots" content="noindex, nofollow" />
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1" />
<link rel="stylesheet" id="cf_styles-css" href="/cdn-cgi/styles/cf.errors.css" type="text/css" media="screen,projection" />
<!--[if lt IE 9]><link rel="stylesheet" id='cf_styles-ie-css' href="/cdn-cgi/styles/cf.errors.ie.css" type="text/css" media="screen,projection" /><![endif]-->
<style type="text/css">body{margin:0;padding:0}</style>
<!--[if lte IE 9]><script type="text/javascript" src="/cdn-cgi/scripts/jquery.min.js"></script><![endif]-->
<!--[if gte IE 10]><!--><script type="text/javascript" src="/cdn-cgi/scripts/zepto.min.js"></script><!--<![endif]-->
<script type="text/javascript" src="/cdn-cgi/scripts/cf.common.js"></script>

</head>
<body>
    <div id="cf-wrapper">
        <div class="cf-alert cf-alert-error cf-cookie-error" id="cookie-alert" data-translate="enable_cookies">Please enable cookies.</div>
        <div id="cf-error-details" class="cf-error-details-wrapper">
            <div class="cf-wrapper cf-header cf-error-overview">
                <h1>
                    <span class="cf-error-type" data-translate="error">Error</span>
                    <span class="cf-error-code">1010</span>
                    <small class="heading-ray-id">Ray ID: 24730841e07509a6 &bull; 2015-11-18 10:36:04 UTC</small>
                </h1>
                <h2 class="cf-subheadline" data-translate="error_desc">Access denied</h2>
            </div><!-- /.header -->

            <section></section><!-- spacer -->

            <div class="cf-section cf-wrapper">
                <div class="cf-columns two">
                    <div class="cf-column">
                        <h2 data-translate="what_happened">What happened?</h2>
                        <p>The owner of this website (coc-servers.com) has banned your access based on your browser's signature (24730841e07509a6-ua48).</p>
                    </div>


                </div>
            </div><!-- /.section -->

            <div class="cf-error-footer cf-wrapper">
    <p>
        <span class="cf-footer-item">CloudFlare Ray ID: <strong>24730841e07509a6</strong></span>
        <span class="cf-footer-separator">&bull;</span>
        <span class="cf-footer-item"><span data-translate="your_ip">Your IP</span>: 64.18.227.167</span>
        <span class="cf-footer-separator">&bull;</span>
        <span class="cf-footer-item"><span data-translate="performance_security_by">Performance &amp; security by</span> <a data-orig-proto="https" data-orig-ref="www.cloudflare.com/5xx-error-landing?utm_source=error_footer" id="brand_link" target="_blank">CloudFlare</a></span>

    </p>
</div><!-- /.error-footer -->


        </div><!-- /#cf-error-details -->
    </div><!-- /#cf-wrapper -->

    <script type="text/javascript">
    window._cf_translation = {};


</script>

</body>
</html>

Хорошо, так что ж- подождите.. Что? Доступ закрыт? Меня забанили? Основано на моем браузере?

Как я могу обойти это? Я знаю, что CloudFlare был создан для предотвращения DDoSing, но это вовсе не DDoS.

Я попытался бы реализовать задержку, однако, ответ от первого до последнего - то же самое сообщение.

Исправит ли реализация нескольких браузерных агентов и задержку, или я готов?

1 ответ

Следуя документам по адресу http://wolfprojects.altervista.org/articles/change-urllib-user-agent/, я смог успешно запустить скрипт без ошибок или из-за запрета облака.

Новый скрипт:

import sys
from urllib import FancyURLopener

servno = 2224 #2000
servernomax = 2676
alldat = ""

class MyOpener(FancyURLopener):
    version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'

mopen = MyOpener()

while True:
    newdat = ""
    url = "http://coc-servers.com/servers/"+str(servno)
    wp = str(mopen.open(url).read())#str(urlopen(url).read())
    #print wp
    ind1 = wp.find('IP: ')
    if ind1 != -1:
        ind1 += 7
        ind2 = wp.find('http',ind1)
        ind3 = wp.find('"',ind2)
        IPurl = wp[ind2:ind3]
        newdat += IPurl
    ind4 = wp.find("<th>Website</th>")
    if ind4 != -1:
        ind4 +=22
        ind5 = wp.find('http',ind4)
        ind6 = wp.find('"',ind5)
        Website = wp[ind5:ind6]
        newdat += ", "
        newdat += Website
    newdat += ";;;  "
    alldat += newdat
    servno +=1
    #print ind1, ind4
    if servno > 2676: break

print alldat
sys.exit()

Кто знал FancyURLOpener было бы так полезно?:)

Другие вопросы по тегам