From c1fc26c1782b0eac0e1fce47074ee96ee21aedc5 Mon Sep 17 00:00:00 2001 From: ubuntu-home Date: Sun, 29 Dec 2019 12:11:42 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90style=E3=80=91=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=B8=8D=E8=A7=84=E8=8C=83=E7=9A=84=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- page_parser/SearchResult.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/page_parser/SearchResult.py b/page_parser/SearchResult.py index f2c6726..7bd4d99 100644 --- a/page_parser/SearchResult.py +++ b/page_parser/SearchResult.py @@ -28,26 +28,28 @@ def __get_page_total(self): soup = BeautifulSoup(r.text, 'html.parser') total = soup.find('span', {'class': 'count'}).text - if len(total) >4: self.__page_total = int(total[2:len(total)-2]) + if len(total) > 4: + self.__page_total = int(total[2:len(total) - 2]) def get_page_links(self): - if self.__page_total == 0: return None + if self.__page_total == 0: + return None - url = self.__result_url + str(self.__current_page*self.__page_size) \ - + '&search_text=' + self.__keyword + url = self.__result_url + str(self.__current_page * self.__page_size) + '&search_text=' + self.__keyword r = requests.get(url) soup = BeautifulSoup(r.text, 'html.parser') soup = soup.find('div', {'class': 'grid-16-8 clearfix'}) links = soup.find_all('a', {'class': ''}) - result = [] - i = 0 + + result, counter = [], 0 for item in links: - i += 1 - if i>self.__page_size: break + counter += 1 + if counter > self.__page_size: + break result.append(str(item.get('href'))) - if self.__current_page < self.__page_size*self.__page_total: + if self.__current_page < self.__page_size * self.__page_total: self.__current_page += 1 return result return None