Python 網頁爬蟲翻頁程式碼
import requests
from bs4 import BeautifulSoup
url =
'https://feebee.com.tw/product/iPhone%20X%20256G%20%E6%99%BA%E6%85%A7%E5%9E%8B%E6%89%8B%E6%A9%9F/?q=iphone%20x&page={}'
page = 1
while True:
res = requests.get(url.format(page))
soup = BeautifulSoup(res.text, 'html.parser')
for iPhone_price in soup.find_all(class_ = 'price ellipsis'):
print('第' + str(page) + '頁:' + iPhone_price.text)
if soup.find(class_ = 'price ellipsis' ) is None:
break
page += 1
沒有留言:
張貼留言