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

作者: garlic774 (蒜頭)   2021-09-19 20:36:05
各位板大好,目前小弟想要爬取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
作者: s0914714 (YA)   2021-09-19 23:41:00
每次抓到的s要append到products
作者: garlic774 (蒜頭)   2021-09-19 23:55:00
成功了!!!謝謝

Links booklink

Contact Us: admin [ a t ] ucptt.com