Skip to content

Commit

Permalink
fix issue that the page element does not exist when the data set size…
Browse files Browse the repository at this point in the history
… is small (#4263)
  • Loading branch information
xiaolongtang committed Nov 10, 2023
1 parent e465002 commit cccc52e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion akshare/currency/currency_china_bank_sina.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def currency_boc_sina(
r = requests.get(url, params=params)
soup = BeautifulSoup(r.text, "lxml")
soup.find(attrs={"id": "money_code"})
page_num = int(soup.find_all("a", attrs={"class": "page"})[-2].text)
page_element_list = soup.find_all("a", attrs={"class": "page"})
page_num = int(page_element_list[-2].text) if len(page_element_list) != 0 else 1
big_df = pd.DataFrame()
for page in tqdm(range(1, page_num + 1), leave=False):
params.update({"page": page})
Expand Down

0 comments on commit cccc52e

Please sign in to comment.