0
Instagramページから、imgタグの親要素を取得しようとしています。BeautifulSoupとPythonを使用して親タグを取得できません
from urllib.request import urlopen
from bs4 import BeautifulSoup
url=urlopen("https://www.instagram.com/people")
html=url.read()
soup=BeautifulSoup(html,"html.parser")
elem=soup.find('img',{'id':'pImage_0'}).parent
print((elem))
誰かが私は親タグまたは私は何をやっている間違いであるを取得することはできませんよ、なぜに私に教えてくださいすることができ:
以下AttributeError:'NoneType' object has no attribute 'parent'
は私の単純なコードは次のとおりです。しかし、私はエラーを取得しています?私はかかわらず、imgタグのコンテンツを取得することができています(コードから親を削除することによって。):
<img alt="Congrats! #CassadeePope is engaged to #AllTimeLow drummer #RianDawson! Get all of the sweet details in our bio link! | #Repost @cassadeepope: WE'RE ENGAGED ❤❤❤❤❤❤❤❤❤❤❤❤❤" class="_icyx7" data-reactid="43" id="pImage_0" src="https://instagram.fdel1-1.fna.fbcdn.net/t51.2885-15/s640x640/sh0.08/e35/16465038_376289889403372_5052986327474110464_n.jpg?ig_cache_key=MTQ0NzUzMjA0NDk1NTIzNDkzNA%3D%3D.2" style="visibility:hidden;"/>
を返します。 'soup.find( 'img'、{'id': 'pImage_0'})'はimgタグ –
のコンテンツを返しました@Naveen Gabrielはそれを印刷して質問に投稿します –