Ich möchte alle iframe
von einer Webseite erhalten.Liste der Wörterbücher Python erstellen
Code:
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)
Ergebnis print(info)
:
{'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'}
Ergebnis pprint(content)
:
[{'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'}]
Warum ist der Wert des Inhalts nicht wahr? Es wird angenommen, dass es derselbe ist wie der Wert, wenn ich print(info)
.
Dank für kurze Erklärung, dies ist mein erster Code mit Python: D. Danke auch für die schnelle Antwort – l1th1um