<s> import urllib2 <EOL> from bs4 import BeautifulSoup <EOL> import pyisbn <EOL> import re <EOL> import time <EOL> import mechanize <EOL> def uread ( isbn ) : <EOL> if len ( isbn ) == <NUM_LIT:10> : <EOL> u_link = "<STR_LIT>" + pyisbn . Isbn10 ( isbn ) . convert ( code = '<STR_LIT>' ) <EOL> else : <EOL> u_link = "<STR_LIT>" + isbn <EOL> br = mechanize . Browser ( ) <EOL> br . set_handle_robots ( False ) <EOL> br . set_handle_refresh ( False ) <EOL> br . addheaders = [ ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> try : <EOL> response = br . open ( u_link ) <EOL> except Exception , e : <EOL> return { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:url>' : u_link } <EOL> u_soup = BeautifulSoup ( response . read ( ) ) <EOL> u_tag = u_soup . select ( '<STR_LIT>' ) <EOL> if not u_tag : <EOL> return { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:url>' : u_link } <EOL> else : <EOL> u_tag = u_tag [ <NUM_LIT:0> ] <EOL> try : <EOL> u_price = re . findall ( r'<STR_LIT>' , str ( u_tag ) ) [ <NUM_LIT:0> ] <EOL> except Exception , e : <EOL> return { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:url>' : u_link } <EOL> return { '<STR_LIT>' : u_price , '<STR_LIT:url>' : u_link } </s>
