#coding:utf-8
import urllib
import http.cookiejar
import json
from lxml import etree
class MyWeb(object):
def httpSendUrl(self,url,params,headers):
if params :
_params = urllib.parse.urlencode(params).encode(encoding='UTF8')
else :
_params =None
req = urllib.request.Request(url, _params, headers)
r = urllib.request.urlopen(req)
html = r.read()
return html.decode("utf-8")
def httpGetUrl(self, url, headers):
return self.httpSendUrl(url,None,headers)
def httpPostUrl(self,url,paras,headers):
return self.httpSendUrl(url, paras, headers)
if __name__ == "__main__":
web = MyWeb()
url = "http://it.zte.com.cn/its/login/ssoLogin.action?rand=1498716317960"
hearders={ 'X-Requested-With': 'XMLHttpRequest',
'Upgrade-Insecure-Requests':'1',
'Connection': 'keep-alive',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Referer': 'http://it.zte.com.cn/',
'Accept-Encoding': 'gzip, deflate, sdch',
'Accept-Language': 'zh-CN,zh;q=0.8',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
}
xxx = web.httpGetUrl(url,hearders)
print(xxx )
tree =etree.HTML(xxx)
nodes =tree.xpath('//li[@class]')
sdf=0
python xpath 例子
最新推荐文章于 2022-08-20 17:59:30 发布