Python 请求库和验证程序。w3.org/nu
我想使用validator.w3.org/nu的API 文件: 我的代码:Python 请求库和验证程序。w3.org/nu,python,python-requests,w3c-validation,Python,Python Requests,W3c Validation,我想使用validator.w3.org/nu的API 文件: 我的代码: validaror_url = "https://validator.w3.org/nu/" headers = { "Content-type": "text/html, charset=utf-8" } ip_address = urllib.quote("http://www.artlebedev.ru/") params = { "doc": ip_address, "out": "json"}
validaror_url = "https://validator.w3.org/nu/"
headers = { "Content-type": "text/html, charset=utf-8" }
ip_address = urllib.quote("http://www.artlebedev.ru/")
params = { "doc": ip_address, "out": "json"}
response = requests.get(validaror_url, headers=headers,
params=params)
我得到:
Response: <Response [200]>
content str: {"url":"http%3A//93.185.180.36/","messages":[{"type":"non-document-error","subType":"io","message":"Missing scheme"}]}\n
响应:
内容字符串:{“url”:“http%3A//93.185.180.36/”,“消息”:[{“类型”:“非文档错误”,“子类型”:“io”,“消息”:“缺少方案”}]}\n
如果我采取另一个样本网站,非文件错误再次出现
此错误在此处被破译:
但无论如何,这样的错误信息不应该存在
如果我将请求更改为unirest,那么一切都很好(有很多消息,它们都是信息性的)。但是unirest不适合我,因为没有Python3支持
我认为,问题可能在于请求不能符合这个“仅”和“作为查询参数分隔符支持。”;“不受支持”(这来自验证程序的文档)
嗯,请求不是教条。我需要的只是从验证器获得一个有意义的响应,而使用Python3。如果请求不合适,也许我应该更改它
你能在这里踢我一脚吗?除了传递url和参数,什么都不要做
import requests
validaror_url = "https://validator.w3.org/nu/"
ip_address = "http://www.artlebedev.ru/"
params = { "doc": ip_address, "out": "json"}
response = requests.get(validaror_url,
params=params)
print(response.json())
这将为您提供如下输出:
{'extract': 'аз... -->\n<table border="0" cellpadding="0" cellspacing="0" width="100%">\n<tr v',
'firstColumn': 1,
'hiliteLength': 63,
'hiliteStart': 10,
'lastColumn': 63,
'lastLine': 1369,
'message': 'The “width” attribute on the “table” element is obsolete. Use CSS instead.',
'type': 'error'},
{'extract': 'аз... -->\n<table border="0" cellpadding="0" cellspacing="0" width="100%">\n<tr v',
'firstColumn': 1,
'hiliteLength': 63,
'hiliteStart': 10,
'lastColumn': 63,
'lastLine': 1369,
'message': 'The “border” attribute on the “table” element is obsolete. Use CSS instead.',
'type': 'error'}
{'extract':'зз…-->\n\n\n\n