0

i need using ip address to get content for example ip address = 157.123.22.11 i need get the organization value Zenith Data Systems

<td>

  Zenith Data Systems</td>

 </tr>

 <tr class="odd">

<th>Organization:</th>

   <td>

      Zenith Data Systems</td>

  </tr>

 </table>

i using urllib2 to get html content, the code from some friends like

 import urllib2
 import lxml.html as lh

 req = urllib2.Request("http://www.ip-adress.com/ip_tracer/157.123.22.11", headers={'User-Agent' : "Magic Browser"})
 html = urllib2.urlopen(req).read()
 doc=lh.fromstring(html)
 print ''.join(doc.xpath('.//*[@class="odd"]')[-1].text_content().split())

but it shows import lxml.html as lh ImportError: No module named lxml.html. So can you give me solution to print the organization name in website, directly get the website content without any new installation like install lxml, my Python is 2.4.3 version

10
  • I'm not sure what you mean by "without any new installation". Is there a reason you can't just install lxml? Your code seems to work okay, and gives me Organization:ZenithDataSystems. Commented Oct 15, 2012 at 3:33
  • i didn't know what is lxml.html? i need install lxml ? Commented Oct 15, 2012 at 3:38
  • from lxml import html as lh Commented Oct 15, 2012 at 3:44
  • @JesseSiu, you want get ip, only? Commented Oct 15, 2012 at 3:45
  • @JesseSiu: yes, it's a separate library, but one that's easy to install. See here for example. @inspectorG4dget: I don't understand -- why would that work if import lxml.html as lh doesn't? Commented Oct 15, 2012 at 3:47

2 Answers 2

1

lxml is not a standard library, so you need to install it.

Install lxml via pip is better:

pip install lxml
Sign up to request clarification or add additional context in comments.

1 Comment

Or use any of the methods described in the installation docs.
0

You'll need to create a class that inherits HTMLParser.HTMLParser. You will also need to implement the handle_starttag, handle_endtag and handle_data methods to parse string HTML.

Check the python docs for details: HTMLParser class

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.