python - BeautifulSoup parsing numbers over text from HTML -


i'm learning python , trying parse data using beautifulsoup. wish print ipv4 rather ipv6 address whatsmyip website. can't seem figure out why parses ipv6 on ipv4 when first occurrence ipv4 address in html tags. appreciate on this.

import urllib2 bs4 import beautifulsoup  page = urllib2.urlopen("http://www.whatsmyip.net") pagehtml = page.read() page.close()  soup = beautifulsoup(pagehtml)  data = soup.find_all("input") input in data:     ip = input.get('value') print ip 

just because ipv6 address last 1 found in <input> element. iterating on <input> elements , result ip variable remembers last one.

try this:

print data[0].get('value')  

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -