Skip to content

Commit

Permalink
fix(google): correct page navigation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
NekoAria committed Sep 24, 2024
1 parent 9b837e6 commit f853a66
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions PicImageSearch/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ async def _navigate_page(
Returns:
GoogleResponse: Updated response after navigating to the specified page, or None if out of range.
"""
index = resp.pages.index(resp.url)
new_index = index + offset
if new_index < 0 or new_index >= len(resp.pages):
next_page_number = resp.page_number + offset
if next_page_number < 1 or next_page_number > len(resp.pages):
return None
_resp = await self.get(resp.pages[new_index])
return GoogleResponse(_resp.text, _resp.url, new_index + 1, resp.pages)
_resp = await self.get(resp.pages[next_page_number - 1])
return GoogleResponse(_resp.text, _resp.url, next_page_number, resp.pages)

async def pre_page(self, resp: GoogleResponse) -> Optional[GoogleResponse]:
"""Navigates to the previous page in Google search results.
Expand Down

0 comments on commit f853a66

Please sign in to comment.