看板 Python 關於我們 聯絡資訊
各位板大好,目前小弟想要爬取1-n頁的特定標題,可目前都只能抓到第n頁 請問哪邊可以做修正呢? 程式碼如下: page = 10 products = [] keyword = "益生菌" for page in range(1, page+1): url = 'https://tw.mall.yahoo.com/search/product?p={}&pg={}'.format(keyword, page) headers = {'User-Agent':"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36"} r = requests.get(url, headers = headers ) soup = BeautifulSoup(r.text,"html.parser") s = soup.find_all('span',class_="BaseGridItem__title___2HWui") s -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.248.146.206 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1632054967.A.4AF.html
s0914714: 每次抓到的s要append到products 09/19 23:41
garlic774: 成功了!!!謝謝 09/19 23:55