[問題] 請問批次抓取 哪邊可以做修正呢?

看板Python作者 (蒜頭)時間3年前 (2021/09/19 20:36), 編輯推噓1(101)
留言2則, 2人參與, 3年前最新討論串1/1
各位板大好,目前小弟想要爬取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

09/19 23:41, 3年前 , 1F
每次抓到的s要append到products
09/19 23:41, 1F

09/19 23:55, 3年前 , 2F
成功了!!!謝謝
09/19 23:55, 2F
文章代碼(AID): #1XHowtIl (Python)
文章代碼(AID): #1XHowtIl (Python)