我有一个简单的 for 循环,它运行但打印每个链接 3 次。为什么?(页面共有 3 个“事件”)我试图从中抓取的网站 = 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贡献1829条经验 获得超6个赞
将最后一个 for 循环更改为:
for item in productlist: productlinks.append(item.a['href'])
添加回答
举报
0/150
提交
取消