亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

For 循環每個鏈接打印 3 個 -Python/BeautifulSoup

For 循環每個鏈接打印 3 個 -Python/BeautifulSoup

茅侃侃 2023-10-26 16:34:34
我有一個簡單的 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'])


查看完整回答
反對 回復 2023-10-26
  • 1 回答
  • 0 關注
  • 160 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號