|
第13.3章擷取電腦相關行業職缺資料 依據本書範例提供的第12行『 page = int(tem.replace('1 / ', '')) 』為取得總頁數,執行出現錯誤
●原始碼 #取得總頁數 html = requests.get(baseurl + '1') soup = BeautifulSoup(html.text, 'lxml') tem = soup.find('select', class_='custom-select').text page = int(tem.replace('1 / ', ''))#出問題點 if page > 15: #最多取15頁資料 page = 15
●問題顯示 ValueError Traceback (most recent call last) <ipython-input-8-ac101bd4e730> in <module> 10 soup = BeautifulSoup(html.text, 'lxml') 11 tem = soup.find('select', class_='custom-select').text ---> 12 page = int(tem.replace('1 / ', '')) 13 if page > 15: #最多取15頁資料 14 page = 15
ValueError: invalid literal for int() with base 10: '\n26\n2 / 26\n3 / 26\n4 / 26\n5 / 26\n6 / 26\n7 / 26\n8 / 26\n9 / 26\n10 / 26\n126\n12 / 26\n13 / 26\n14 / 26\n15 / 26\n16 / 26\n17 / 26\n18 / 26\n19 / 26\n20 / 26\n226\n22 / 26\n23 / 26\n24 / 26\n25 |