웹 페이지에서 iframe
을 모두 가져오고 싶습니다.사전 파이썬 목록 작성
코드 :
site = "http://" + url
f = urllib2.urlopen(site)
web_content = f.read()
soup = BeautifulSoup(web_content)
info = {}
content = []
for iframe in soup.find_all('iframe'):
info['src'] = iframe.get('src')
info['height'] = iframe.get('height')
info['width'] = iframe.get('width')
content.append(info)
print(info)
pprint(content)
결과 print(info)
의 : pprint(content)
의
{'src': u'abc.com', 'width': u'0', 'height': u'0'}
{'src': u'xyz.com', 'width': u'0', 'height': u'0'}
{'src': u'http://www.detik.com', 'width': u'1000', 'height': u'600'}
결과 :
[{'height': u'600', 'src': u'http://www.detik.com', 'width': u'1000'},
{'height': u'600', 'src': u'http://www.detik.com', 'width': u'1000'},
{'height': u'600', 'src': u'http://www.detik.com', 'width': u'1000'}]
왜 컨텐츠의 가치를 잘 작성하지 못했습니다입니까? 내가 print(info)
일 때의 값과 같다고 가정합니다.
감사합니다, 이것은 파이썬을 사용하여 내 첫 번째 코드입니다. 또한 빠른 응답을 주셔서 감사합니다 – l1th1um