<s> import urllib2 <EOL> from lxml import etree <EOL> from constants import * <EOL> def get_qrcode_full_url ( ) : <EOL> response = urllib2 . urlopen ( WEIXIN_QRCODE_PAGE ) <EOL> html = response . read ( ) <EOL> tree = etree . HTML ( html ) <EOL> for image in tree . xpath ( "<STR_LIT>" ) : <EOL> if image . attrib . has_key ( '<STR_LIT:class>' ) : <EOL> if QRCODE_TAG_CLASSES in image . attrib [ '<STR_LIT:class>' ] : <EOL> imageUrl = image . attrib [ '<STR_LIT:src>' ] <EOL> qrcodeFullUrl = WEIXIN_LOGIN_DOMAIN + imageUrl <EOL> return qrcodeFullUrl <EOL> def get_qrcode_image_from_url ( qrcodeFullUrl ) : <EOL> response = urllib2 . urlopen ( qrcodeFullUrl ) <EOL> image = response . read ( ) <EOL> return image <EOL> def get_qrcode_image ( ) : <EOL> qrcodeFullUrl = get_qrcode_full_url ( ) <EOL> return get_qrcode_image_from_url ( qrcodeFullUrl ) </s>
