add cninfo announcement

This commit is contained in:
hillerliao
2019-12-15 21:52:58 +08:00
parent 7dc1508458
commit 65a4a5b7a8
24 changed files with 639 additions and 573 deletions

View File

@@ -1,25 +1,25 @@
from flask import Response
import requests
from parsel import Selector
DEFAULT_HEADERS = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'}
class XMLResponse(Response):
def __init__(self, response, **kwargs):
if 'mimetype' not in kwargs and 'contenttype' not in kwargs:
if response.startswith('<?xml'):
kwargs['mimetype'] = 'application/xml'
return super().__init__(response, **kwargs)
def fetch(url: str, headers: dict=DEFAULT_HEADERS, proxies: dict=None):
try:
res = requests.get(url, headers=headers, proxies=proxies)
res.raise_for_status()
except Exception as e:
print(f'[Err] {e}')
else:
html = res.text
tree = Selector(text=html)
return tree
from flask import Response
import requests
from parsel import Selector
DEFAULT_HEADERS = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'}
class XMLResponse(Response):
def __init__(self, response, **kwargs):
if 'mimetype' not in kwargs and 'contenttype' not in kwargs:
if response.startswith('<?xml'):
kwargs['mimetype'] = 'application/xml'
return super().__init__(response, **kwargs)
def fetch(url: str, headers: dict=DEFAULT_HEADERS, proxies: dict=None):
try:
res = requests.get(url, headers=headers, proxies=proxies)
res.raise_for_status()
except Exception as e:
print(f'[Err] {e}')
else:
html = res.text
tree = Selector(text=html)
return tree