Skip to content

Commit

Permalink
Fix album download failed
Browse files Browse the repository at this point in the history
closes #3
  • Loading branch information
einverne committed Jul 14, 2020
1 parent 08d05fd commit 5eea3ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions douban/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# -*- coding:utf-8 -*-
import os

import requests
from bs4 import BeautifulSoup

from douban import threadPoolExecutor
Expand All @@ -29,7 +28,7 @@ def photos(self):

def __photos(self, start):
url = self.url + str(start)
r = requests.get(url)
r = file_utils.request_with_headers(url)
soup = BeautifulSoup(r.text, "html.parser")
return soup.find_all("div", class_="photo_wrap")

Expand Down
9 changes: 9 additions & 0 deletions utils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ def get_raw_url(thumb_url):
if 'photo/lthumb' in thumb_url:
thumb_url = thumb_url.replace("photo/lthumb", "photo/large")
return thumb_url


headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'
}


def request_with_headers(url):
return requests.get(url, headers=headers)

0 comments on commit 5eea3ee

Please sign in to comment.