0

Как отвалидировать несколько сайтов одновременно. Сразу на нескольких сервисах? Произойдет валидация сайта, если я отправлю самый обыкновенный get-запрос на https://validator.w3.org/check?uri=[ссылка]

r = requests.get('https://validator.w3.org/check?uri=http://shost-craft.su') 

Или же надо посылать специальные headers или специальный запрос, который даст сайту знать что надо именно отвалидировать сайт. По типу:

`r = requests.get('https://validator.w3.org/check?uri=http://shost-craft.su', headers={'Тут что-то для валидации'}`
 print(r.headers)

Пришли headers:

{'Accept-Encoding': 'gzip',
 'Access-Control-Allow-Headers': 'content-type',
 'Access-Control-Allow-Origin': '*',
 'Cache-Control': 'no-cache',
 'Content-Encoding': 'gzip',
 'Content-Type': 'text/html; charset=UTF-8',
 'Date': 'Sun, 07 May 2017 20:17:42 GMT',
 'Expires': 'Thu, 01 Jan 1970 00:00:00 GMT',
 'Public-Key-Pins': 'pin-sha256="cN0QSpPIkuwpT6iP2YjEo1bEwGpH/yiUn6yhdy+HNto="; '
                    'pin-sha256="WGJkyYjx1QMdMe0UqlyOKXtydPDVrk7sl2fV+nNm1r4="; '
                    'pin-sha256="LrKdTxZLRTvyHM4/atX2nquX9BeHRZMCxg3cf4rhc2I="; '
                    'max-age=864000',
 'Server': 'Jetty(9.2.9.v20150224)',
 'Strict-Transport-Security': 'max-age=15552015; preload',
 'Transfer-Encoding': 'chunked',
 'Vary': 'Accept-Encoding, User-Agent',
 'X-Frame-Options': 'deny',
 'X-XSS-Protection': '1; mode=block'}

Но я не вижу никакого смысла в данных headers. Или тут все таки есть что-то что обозначает прошло валидацию или нет?

Так же есть сам r.text: <!DOCTYPE html> <html lang="en"><head><link href="icon.png" rel="icon"><link href="style.css" rel="stylesheet"><title>Showing results for http://shost-craft.su/ - Nu Html Checker</title><meta name="viewport" content="width=device-width, initial-scale=1"></head><body><div id="banner"><h1 id="title"><a href="."><span>Nu Html Checker</span></a></h1></div><p class="disclaimer">This tool is an ongoing experiment in better HTML checking, and its behavior remains subject to change</p><h2 id="top">Showing results for http://shost-craft.su/</h2><form method="get"><fieldset><legend>Checker Input</legend><p class="checkboxes">Show <span class="checkboxgroup"><label title="Display the markup source of the input document." for="showsource"><input type="checkbox" name="showsource" id="showsource" value="yes">source</label><label title="Display an outline of the input document." for="showoutline"><input type="checkbox" name="showoutline" id="showoutline" value="yes">outline</label><label title="Display a report about the textual alternatives for images." for="showimagereport"><input type="checkbox" name="showimagereport" id="showimagereport" value="yes">image report</label></span><input id="show_options" type="button" value="Options…"><span class="extraoptions hidden"><span class="checkboxgroup"><label title="Check the content of all responses, including (non-200) error responses"><input type="checkbox" name="checkerrorpages" id="checkerrorpages" value="yes">check error pages</label></span><label id="user-agent-label" title="Specify the user-agent string to send in the document request">User-Agent <input name="useragent" list="useragents" value="Validator.nu/LV http://validator.w3.org/services"></label><datalist id="useragents"></datalist></span></p><div id="inputregion"><label id="inputlabel" for="doc">Document URL:</label><input type="url" name="doc" id="doc" pattern="(?:(?:https?://.+)|(?:data:.+))?" title="Absolute IRI (http, https or data only) of the document to be checked." tabindex="0" autofocus="autofocus" value="http://shost-craft.su/"></div><p><input value="Check" type="submit" id="submit"></p></fieldset></form><script src="script.js"></script><div id="results"><ol><li class="error"><p><strong>Error</strong>: <span><code>style</code> element between <code>head</code> and <code>body</code>.</span></p><p class="location">From line <span class="first-line">14</span>, column <span class="first-col">5</span>; to line <span class="last-line">14</span>, column <span class="last-col">11</span></p><p class="extract"><code>head&gt;<span class="lf" title="Line break">↩</span> <b>&lt;style&gt;</b><span class="lf" title="Line break">↩</span> b</code></p></li><li class="error fatal"><p><strong>Fatal Error</strong>: <span>Cannot recover after last error. Any further errors will be ignored.</span></p><p class="location">From line <span class="first-line">14</span>, column <span class="first-col">5</span>; to line <span class="last-line">14</span>, column <span class="last-col">11</span></p><p class="extract"><code>head&gt;<span class="lf" title="Line break">↩</span> <b>&lt;style&gt;</b><span class="lf" title="Line break">↩</span> b</code></p></li></ol><p class="failure">There were errors.</p><div class="details"><p class="msgschema">Used the schema for HTML with SVG 1.1, MathML 3.0, RDFa 1.1, and ITS 2.0 support.</p><p class="msgmediatype">Used the HTML parser. Externally specified character encoding was UTF-8.</div><p class="stats">Total execution time 340 milliseconds.</p></div><hr><div id="about"><p><a href="about.html">About this checker</a> • <a href="about.html#issues">Report an issue</a> • <span class="version">Version: 17.5.7</span></p></div></body></html>

8
  • В ответе, который валидатор вам присылает после вашего запроса, вы по каким-то причинам не нашли ответов на свои вопросы?
    – andreymal
    7 мая 2017 в 20:16
  • @andreymal я изменил вопрос, если честно я не нашел никаких факторов что прошло валидацию 7 мая 2017 в 20:22
  • headers отпечатали, теперь собственно сам ответ отпечатайте-то :)
    – andreymal
    7 мая 2017 в 21:06
  • @andreymal <Response [200]> это то или нет? 7 мая 2017 в 21:07
  • 1
    Выполните запрос в адресной строке браузера. Вы перейдёте на сайт. Найдите там ответ на вопрос о валидации. Затем в браузере откройте исходный код. Вы увидите, что он совпадает выводом r.text в вашем коде. Теперь формулировка: найдите в r.text элементы совпадающие с таковыми в браузере. В качестве почитать я бы посоветовал Райн Митчел "Скрапинг веб-сайтов с помощью python". Там есть ответы на все ваши вопросы. 8 мая 2017 в 20:56

1 ответ 1

0

Как насчет такой валидации c помощью aiohttp и asyncio? Код:

import random
import asyncio
from aiohttp import ClientSession

async def fetch(url, session):
    async with session.get(url) as response:
        delay = response.headers.get("DELAY")
        date = response.headers.get("DATE")
        print("{}:{} with delay {}".format(date, response.url, delay))
        return await response.read()


async def bound_fetch(sem, url, session):
    async with sem:
        await fetch(url, session)


async def run(r):
    site = "http://shost-craft.su"


    with open("C:\\cruelnetwork\\cruel.need\\wolfs.txt") as werewolves:
            array = [row.strip()+site for row in werewolves]
    for url in array:
        tasks = []

        sem = asyncio.Semaphore(1000)
        print(url)

        async with ClientSession() as session:
            for i in range(r):

                task = asyncio.ensure_future(bound_fetch(sem, url.format(i), session))
                tasks.append(task)

            responses = asyncio.gather(*tasks)
            await responses

number = 10
loop = asyncio.get_event_loop()

future = asyncio.ensure_future(run(number))
loop.run_until_complete(future)

Нашел https://pawelmhm.github.io/asyncio/python/aiohttp/2016/04/22/asyncio-aiohttp.html. Или тут лучше что-то подправить? :)

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.