Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Tuesday, April 10, 2012

Upgrade to Python 2.5.6 on RHEL 5.5

Here are upgrade instructions for Python 2.4 to Python 2.5.6:
1. http://www.python.org/ftp/python/2.5.6/Python-2.5.6.tgz
2. tar xzf Python-2.5.6.tgz
3. cd Python-2.5
4. ./configure
5. $ make
6. sudo make altinstall
7. sudo mv /usr/bin/python /usr/bin/python_old_2.4
8. sudo ln -s  /usr/local/bin/python2.5 /usr/bin/python

Validate:
# python -V
Python 2.5.6

Tuesday, December 13, 2011

Scraping

LXML is useful Python library for scraping. Here is an example of scraping script

pip install requests
pip install lxml

#! /usr/bin/python
import requests
import lxml
from lxml import html

r = requests.get('https://www.google.com/')
tree = lxml.html.fromstring(r.content)
elements = tree.get_element_by_id("prm")
for el in elements:
print el.text_content()

Note: It works with Python 2.6.1 (did not work with Python 4). LXML specs