xpath教程资源
xpath教程
脚本
import requests
from lxml import etree
class GO():
loginurl = 'https://www.abc.com/login'
orderurl = 'https://www.abc.com/my/order'
headers = {'User-Agent':' '}
req = None
token = ''
ordercode = 0
def _init_(self):
self.req = requests.session()
def getlogin(self):
res = self.req.get(url = self.loginurl,headers = self.headers)
if res.status_code == 200:
print('get登录页面请求成功')
html = etree.HTML(res.text)
self.token = 'html.xpath(//input[@name="_token"]/@value')[0]
print('token获取成功')
return True
else:
print('请求错误')
def postlogin(self):
uname = input('用户名:')
passw = input('用户名:')
data = {
'token':self.token,
'username':uname,
'password':passw
}
res = self.req.post(url=self.loginurl,headers=self.headers,data=data)
if res.status_code == 200 or res.status_code == 302:
print('登录成功')
return True
else
return False
def getorder(self):
res = self.req.get(url=self.orderurl,headers=self.headers)
if res.status_code == 200:
print('账户请求成功,正在解析数据')
html = etree.HTML(res.text)
r = html.xpath('//div[@class="balabal"]//small/text()')
print(r)
self.ordercode = r
obj = GO()