通过xpath获取页面html代码
1 from lxml import etree
2 import requests
3 res=requests.get('http://www.w3school.com.cn/')
4 tree=etree.HTML(res.content)
5 div=tree.xpath('//div[@id="d1"]')[0]
6 div_str=etree.tostring(div,encoding='utf-8')
7 print div_str
1 from lxml import etree
2 import requests
3 res=requests.get('http://www.w3school.com.cn/')
4 tree=etree.HTML(res.content)
5 div=tree.xpath('//div[@id="d1"]')[0]
6 div_str=etree.tostring(div,encoding='utf-8')
7 print div_str