Environment:
Window 7
Python 2.7.6
Chrome
I am using python 2.7.6 and trying to download the image from the following link. Only 1 image in the link.
But I failed get the address of the image using lxml. Here is my code.
from urllib2 import urlopen
from lxml import etree
import lxml.html
url = 'http://charts.aastocks.com/servlet/Charts?fontsize=12&15MinDelay=T&lang=0&titlestyle=1&vol=1&Indicator=1&indpara1=10&indpara2=20&indpara3=50&indpara4=100&indpara5=150&subChart1=2&ref1para1=14&ref1para2=0&ref1para3=0&subChart2=3&ref2para1=12&ref2para2=26&ref2para3=9&subChart3=12&ref3para1=0&ref3para2=0&ref3para3=0&scheme=3&com=100&chartwidth=1254&chartheight=1058&stockid=110000.HK&period=6&type=1&logoStyle=1&'
tree = etree.HTML(urlopen(url).read())
for img in tree.xpath('/html/body/img'):
img_attr = img.attrib
print (img_attr["src"])
Thereafter, I add the following code to print out the html using pretty_print function
print(etree.tostring(tree, pretty_print=True))
And python return the following
OUTPUT
<html>
<body>
<p>GIF89aæ ÷ ))66(??/EE3CC299*,,! 33&II6\\EiiNooSkkP[[D//#
ÿÿÿ
##VV@ttVŒiŠ•y1jˆ_‰–pddKDD3&&==-]]E‚‚a¨¨~•«’+p’ RŽXŽ–±‡†‡cYYB$$__G‡‡e°²†›¶ j” TŽ SŽ Oސ³¡£wAA0!!XXBƒƒb¬¯…ƒ¨ž[ UŒ ZŒWŒ GŽ…¯“¶¸…zz[KK8''uuW¢}n™˜X4u’Œ±˜_–šMkžÄÈ’‰‰fWWA</p>
</body>
</html>
It seem python didn't get the correct html code from the link, is there any way I can get the image address? Thanks :)