From 964ddf697fbb116be14d0bf5a37cf89fb25aedbd Mon Sep 17 00:00:00 2001 From: doubaniux Date: Tue, 12 May 2020 14:20:50 +0800 Subject: [PATCH] fix book form cover url error --- common/forms.py | 3 ++- common/scraper.py | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/common/forms.py b/common/forms.py index a13145cd..15180200 100644 --- a/common/forms.py +++ b/common/forms.py @@ -2,6 +2,7 @@ from django import forms from django.contrib.postgres.forms import JSONField from django.core.exceptions import ValidationError from django.utils.translation import gettext_lazy as _ +from boofilsic.settings import MEDIA_URL import json @@ -66,7 +67,7 @@ class ImageInput(forms.FileInput): Return the file object if it has a defined url attribute. """ if self.is_initial(value): - return value + return MEDIA_URL + value def is_initial(self, value): """ diff --git a/common/scraper.py b/common/scraper.py index 61a277d4..9c539a92 100644 --- a/common/scraper.py +++ b/common/scraper.py @@ -24,8 +24,8 @@ DEFAULT_REQUEST_HEADERS = { TIMEOUT = 10 # luminati account credentials -USERNAME = '***REMOVED***' -PASSWORD = '***REMOVED***' +USERNAME = 'lum-customer-hl_124-zone-static' +PASSWORD = 'tvt' PORT = 22225 @@ -37,8 +37,8 @@ def scrape_douban_book(url): 'http': proxy_url, 'https': proxy_url, } - # r = requests.get(url, proxies=proxies, headers=DEFAULT_REQUEST_HEADERS, timeout=TIMEOUT) - r = requests.get(url, headers=DEFAULT_REQUEST_HEADERS, timeout=TIMEOUT) + r = requests.get(url, proxies=proxies, headers=DEFAULT_REQUEST_HEADERS, timeout=TIMEOUT) + # r = requests.get(url, headers=DEFAULT_REQUEST_HEADERS, timeout=TIMEOUT) content = html.fromstring(r.content.decode('utf-8')) @@ -103,7 +103,7 @@ def scrape_douban_book(url): 'cache-control': 'no-cache', 'dnt': '1' , }, - # proxies=proxies, + proxies=proxies, timeout=TIMEOUT, ) if img_response.status_code == 200: