beautifulsoupを使用して、a tagの href の値と、img タグの src を取得したいです。
hrefは取得できるようになったのですが、同試行錯誤してもimg の src の値が取得できません。
アドバイスいただけないでしょうか?
どうぞよろしくお願いします。
python
1import bs4 2 3text = driver.page_source 4soup = bs4.BeautifulSoup(text, features='lxml') 5elems = soup.find_all('a') 6added_count=0 7for elem in elems: 8 9 post_p= elem["href"] 10 11 if '/p/' in post_p: 12 added_count=added_count+1 13 print('count '+str(added_count)) 14 print('post='+post_p) 15 16 # download_url=elem.attrs['src'] 17 url = elem["src"] <---- エラーが出ます 18 print('url='+url) 19
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。