1 Star 0 Fork 0

fanyangchu/wydomain

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
common.py 2.70 KB
一键复制 编辑 原始数据 按行查看 历史
ring04h 提交于 2016-11-01 13:49 . path check
# encoding: utf-8
import re
from config import *
import json
import subprocess
import logging
import requests as requests
import requests as __requests__
# from tldextract import extract, TLDExtract
from utils.fileutils import FileUtils
import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()
if allow_http_session:
requests = requests.Session()
def is_domain(domain):
domain_regex = re.compile(
r'(?:[A-Z0-9_](?:[A-Z0-9-_]{0,247}[A-Z0-9])?\.)+(?:[A-Z]{2,6}|[A-Z0-9-]{2,}(?<!-))\Z',
re.IGNORECASE)
return True if domain_regex.match(domain) else False
def http_request_get(url, body_content_workflow=False, allow_redirects=allow_redirects, custom_cookie=""):
try:
if custom_cookie:
headers['Cookie']=custom_cookie
result = requests.get(url,
stream=body_content_workflow,
headers=headers,
timeout=timeout,
proxies=proxies,
allow_redirects=allow_redirects,
verify=allow_ssl_verify)
return result
except Exception, e:
# return empty requests object
return __requests__.models.Response()
def http_request_post(url, payload, body_content_workflow=False, allow_redirects=allow_redirects, custom_cookie=""):
""" payload = {'key1': 'value1', 'key2': 'value2'} """
try:
if custom_cookie:
headers['Cookie']=custom_cookie
result = requests.post(url,
data=payload,
headers=headers,
stream=body_content_workflow,
timeout=timeout,
proxies=proxies,
allow_redirects=allow_redirects,
verify=allow_ssl_verify)
return result
except Exception, e:
# return empty requests object
return __requests__.models.Response()
def curl_get_content(url):
try:
cmdline = 'curl "{url}"'.format(url=url)
logging.info("subprocess call curl: {}".format(url))
run_proc = subprocess.Popen(
cmdline,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(stdoutput,erroutput) = run_proc.communicate()
response = {
'resp': stdoutput.rstrip(),
'err': erroutput.rstrip(),
}
return response
except Exception as e:
pass
def save_result(filename, args):
try:
fd = open(filename, 'w')
json.dump(args, fd, indent=4)
finally:
fd.close()
def read_json(filename):
if FileUtils.exists(filename):
try:
fd = open(filename, 'r')
args = json.load(fd)
return args
finally:
fd.close()
else:
return []
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fanych/wydomain.git
git@gitee.com:fanych/wydomain.git
fanych
wydomain
wydomain
wydomain2

搜索帮助