|
|
|
@ -35,13 +35,35 @@ def getsource(url):
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
def useRequests(url):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def saveCookies(response):
|
|
|
|
|
myCookies = {}
|
|
|
|
|
for key, value in response.cookies.items():
|
|
|
|
|
myCookies[key] = value
|
|
|
|
|
jsonCookies = json.dumps(myCookies)
|
|
|
|
|
with open(settings.COOKIES_FILENAME, mode = 'a', encoding = 'utf-8') as fd:
|
|
|
|
|
fd.write(jsonCookies)
|
|
|
|
|
print("Cookies saved!")
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
res = requests.get(url, headers = headers)
|
|
|
|
|
res.raise_for_status() # 判断是不是200
|
|
|
|
|
res.encoding = res.apparent_encoding
|
|
|
|
|
print(res.cookies)
|
|
|
|
|
saveCookies(res)
|
|
|
|
|
return res
|
|
|
|
|
except BaseException as e:
|
|
|
|
|
print(e)
|
|
|
|
|
print("sth wrong in your downloader.useRequests. Exiting...")
|
|
|
|
|
exit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
jdurl = "https://item.jd.com/10036840192083.html"
|
|
|
|
|
url = "https://www.vveby.com/search?keyword=" + jdurl
|
|
|
|
|
with open('historyPrice.html', 'w+', encoding = 'utf-8') as fd:
|
|
|
|
|
fd.write(getsource(url))
|
|
|
|
|
fd.close()
|
|
|
|
|
# jdurl = r"https://item.jd.com/10036840192083.html"
|
|
|
|
|
jdurl = r"https://item.jd.com/59162092942.html"
|
|
|
|
|
url = r"https://www.vveby.com/search?keyword=" + jdurl
|
|
|
|
|
print(url)
|
|
|
|
|
with open('newhistoryPrice.html', 'w+', encoding = 'utf-8') as fd:
|
|
|
|
|
fd.write(useRequests(url).text)
|
|
|
|
|
print('done')
|