[英]Read the page number while scraping a website using BeautifulSoup
我正在嘗試僅從URL鏈接中讀取頁號並將其放入變量中。 下面是我從網站上抓取的變量的打印輸出
<li><a href="https://bp.portwallet.com/report/topUp?source=gp_web&allSearch=&amountFrom=1&amountTo=50000&startdate=2018-10-03&enddate=2018-10-03&topUpSearch=topUpSearch&status=1&rType=Prepaid&per_page=46">Last ›</a></li>
我需要將per_page =值放入變量中。
我試着只刮號碼而沒有運氣
from bs4 import BeautifulSoup
page = '''<li><a href="https://bp.portwallet.com/report/topUp?source=gp_web&allSearch=&amountFrom=1&amountTo=50000&startdate=2018-10-03&enddate=2018-10-03&topUpSearch=topUpSearch&status=1&rType=Prepaid&per_page=46">Last ›</a></li>'''
soup = BeautifulSoup(page, 'html.parser')
x = soup.select('a')
per_page = (x[0]['href']).split('per_page=')[-1]
print('per_page:', per_page)
輸出:
per_page: 46
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.