fixt
This commit is contained in:
parent
2553de0a9d
commit
ebb49ce04c
@ -11,7 +11,7 @@ class htmlUtils:
|
|||||||
url_data = {}
|
url_data = {}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def getHTML(cls, curl):
|
def getHTML(cls, curl,type=None):
|
||||||
rstr = r"[\/\\\:\*\?\"\<\>\|\.]" # '/ \ : * ? " < > |'
|
rstr = r"[\/\\\:\*\?\"\<\>\|\.]" # '/ \ : * ? " < > |'
|
||||||
#file_url = re.sub(rstr, "_", curl)
|
#file_url = re.sub(rstr, "_", curl)
|
||||||
keys = cls.url_data.keys()
|
keys = cls.url_data.keys()
|
||||||
@ -29,7 +29,10 @@ class htmlUtils:
|
|||||||
try:
|
try:
|
||||||
print("请求地址:",curl)
|
print("请求地址:",curl)
|
||||||
res = s.get(curl,stream=True, headers=cls.headers, timeout=20)
|
res = s.get(curl,stream=True, headers=cls.headers, timeout=20)
|
||||||
url_text = html.fromstring(res.text)
|
if type == "json":
|
||||||
|
url_text = res.json()
|
||||||
|
else:
|
||||||
|
url_text = html.fromstring(res.text)
|
||||||
except:
|
except:
|
||||||
print(f'Retry! 第{count}次')
|
print(f'Retry! 第{count}次')
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
@ -43,15 +46,9 @@ class htmlUtils:
|
|||||||
cls.url_data.update(data)
|
cls.url_data.update(data)
|
||||||
return url_text
|
return url_text
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def getBytes(cls, url):
|
|
||||||
return requests.get(url, headers=cls.headers,stream=True,timeout=30)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def getJSON(cls,curl):
|
def getJSON(cls,curl):
|
||||||
res = requests.get(curl, headers=cls.headers,timeout=30)
|
return cls.getHTML(curl,type="json")
|
||||||
data_json = res.json()
|
|
||||||
return data_json
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def xpathData(cls,c_xpath,url=None,num=None,not_eq=None):
|
def xpathData(cls,c_xpath,url=None,num=None,not_eq=None):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user