मैं एक वेबपृष्ठ से सभी 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)
का परिणाम:
{'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'}
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'}]
क्यों सामग्री के मूल्य सही नहीं है? ऐसा लगता है कि जब मैं print(info)
पर मान के समान होना चाहिए।
संक्षिप्त विवरण के लिए धन्यवाद, यह मेरी पहली अजगर का उपयोग कर कोड है। त्वरित प्रतिक्रिया – l1th1um