2017-02-11 15 views
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;"/> 

答えて

0

このページではJavaScriptによってロードされ、IMGタグはJSによって生成され、要求は唯一のHTMLコードを返します、そう、あなたはHTMLコードを取得することはできませんし、

soup.find('img',{'id':'pImage_0'}) 

は真実ではありませんNone

+0

を返します。 'soup.find( 'img'、{'id': 'pImage_0'})'はimgタグ –

+0

のコンテンツを返しました@Naveen Gabrielはそれを印刷して質問に投稿します –

関連する問題