【Python】【爬蟲】requests+lxml模擬登錄爬取信息

要求:通過爬蟲技術,模擬用戶登錄龍池網站,爬取用戶的相關信息(昨日算力,昨日收益)

問題:龍池的網站需要滑動解鎖纔可登錄

一.模擬登錄

1.使用會話訪問主頁,抓取主頁中的token

import requests
from lxml import etree

s = requests.Session()
r = s.get("https://www.dpool.top/index")
html = etree.HTML(r.text)
node = html.xpath('//*[@id="forgetPwd"]/div/div[2]/form/input[1]')[0]
token = node.get('value')

注意:token是動態變化的,每次登錄時都需要抓取

2.配置參數、首部,模擬登錄

r = s.post("https://www.dpool.top/pools/login", headers = {'X-CSRF-TOKEN':token, 'Referer':'https://www.dpool.top/index'}
, params = {'email':'***********@163.com', 'password':'********'})
注意:如果不在headers添加token,r.status_code會打印500錯誤

二.獲取數據並解析

r = s.get("https://www.dpool.top/pools/ajax-worker-stats", headers = {'Referer':'https://www.dpool.top/pools/dashboard'})
value = r.json()['shares_24h']
print value, "T/S"

r = s.get("https://www.dpool.top/pools/subaccount-list/?curr=1&nums=10", headers = {'Referer':'https://www.dpool.top/pools/subaccount'})
value = r.json()['data'][1]['profit']
print value

獲得的數據爲josn結構,可以通過response的json()函數直接提取

三.打印結果

<--dpool_BTC-->liang_06
91.34 T/S
0.00543674

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章