File: _web_example2.py

package info (click to toggle)
nodebox-web 1.9.4.6-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,900 kB
  • sloc: python: 7,582; ansic: 581; xml: 239; makefile: 2
file content (24 lines) | stat: -rw-r--r-- 614 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Parsing web pages.

import web

url = "http://nodebox.net"
print web.url.is_webpage(url)

# Retrieve the data from the web page and put it in an easy object.
html = web.page.parse(url)

# The actual URL you are redirected to.
# This will be None when the page is retrieved from cache.
print html.redirect

# Get the web page title.
print html.title

# Get all the links, including internal links in the same site.
print html.links(external=False)

# Browse through the HTML tree, find <div id="content">,
# strip tags from it and print out the contents.
content = html.find(id="content")
web.html.plain(content)