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

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -