[M]jandan_pic_url to https

This commit is contained in:
Ching 2021-06-11 11:05:11 +08:00
parent f24b8ae4ee
commit e8bf2c2044

View File

@ -65,20 +65,14 @@ def toot(proxy=None):
while page_count and jandan_pic_url: while page_count and jandan_pic_url:
resp = session.get(jandan_pic_url, timeout=2) resp = session.get(jandan_pic_url, timeout=2)
retry_count = 5 if resp.status_code != 200:
if resp.status_code != 200 and retry_count:
proxy = get_proxy().get('proxy')
session.proxies.update({"https": "https://{}".format(proxy)})
time.sleep(10) time.sleep(10)
retry_count -= 1
continue continue
if retry_count <= 0 and resp.status_code != 200:
raise ValueError('http status not 200')
soup = BeautifulSoup(resp.content, 'html.parser') soup = BeautifulSoup(resp.content, 'html.parser')
jandan_pic_url = soup.find(class_='previous-comment-page')['href'] jandan_pic_url = soup.find(class_='previous-comment-page')['href']
page_count -= 1 page_count -= 1
if jandan_pic_url.startswith('//'): if jandan_pic_url.startswith('//'):
jandan_pic_url = 'http:' + jandan_pic_url jandan_pic_url = 'https:' + jandan_pic_url
pic_nodes = soup.find('ol').find_all('li') pic_nodes = soup.find('ol').find_all('li')