我有一個(gè)簡單的 for 循環(huán),它運(yùn)行但打印每個(gè)鏈接 3 次。為什么?(頁面共有 3 個(gè)“事件”)我試圖從中抓取的網(wǎng)站 = https://www.aacr.org/get-involved/events/這是代碼->import requestsfrom bs4 import BeautifulSoupimport pandas as pdproductlinks = []url='https://www.aacr.org/get-involved/events/'r=requests.get(url)soup=BeautifulSoup(r.content,'html.parser')productlist=soup.find_all('article',class_='event')for item in productlist: for link in item.find_all('a',href=True): productlinks.append(link['href'])print(productlinks)Any insights on how i can make it run 1 per link
1 回答

肥皂起泡泡
TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超6個(gè)贊
將最后一個(gè) for 循環(huán)更改為:
for item in productlist: productlinks.append(item.a['href'])
添加回答
舉報(bào)
0/150
提交
取消