到这里,爬取网页的代码基本完了,我又发现了一个问题,这个url后面的一串数字是啥?
又是漫长的试验和搜索,最后得出结论,就是个随机数,没有规律,好像仅仅是为了缓存相关的用途
至此,我们的代码也就出来了
#requests库的几个参数
base_url = '
http://act2.dn.sdo.com/Project/202004ranking/handler/GetStageRank.ashx?'
#给url加随机数
url = base_url + str(random.random())
headers = { 'Host': 'act2.dn.sdo.com', 'Referer': '
http://act2.dn.sdo.com/Project/202004ranking/', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36', 'X-Requested-With': 'XMLHttpRequest', 'Content-Length': '57', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }
#职业代码
jobcode = { '23':'剑皇','24':'月之领主','25':'狂战士','26':'毁灭者','76':'黑暗复仇者', '29':'狙翎','30':'魔羽','31':'影舞者','32':'风行者','81':'银色猎人', '35':'火舞','36':'冰灵','37':'时空领主','38':'黑暗女王','85':'黑暗死神', '41':'圣骑士','42':'十字军','43':'圣徒','44':'雷神','83':'黑暗教主', '47':'重炮手','48':'机械大师','50':'炼金圣士','51':'药剂师', '87':'银色机甲师', '55':'黑暗萨满','56':'噬魂者','59':'灵魂舞者','58':'刀锋舞者','89':'银色舞灵', '63':'烈','64':'影','68':'曜','69':'暗','91':'黑暗修罗', '73':'皇家骑士','74':'魔枪骑士','93':'冰魂术士','94':'火灵术士','99':'黑暗破魔师', '78':'御灵','79':'破风','96':'碎夜','97':'驭光', '102':'斩魄','103':'逐月'}
#区服代码
seacode = { '华东电信一区':'1','华南电信一区':'2','华中电信一区':'4','华东电信二区':'5', '全国网通一区':'7','南方电信大区':'18','WEGAME一区1服':'401','WEGAME一区234服':'402','WEGAME二区':'41', 'WEGAME三区':'42'}
#传递的参数data = { 'PageIndex':'1', 'Pagesize':'5', 'JobCode':'0', 'SeaAreaId':'0', 'PassNum':'0'}
#爬回的结果
r = requests.post(url, data = data, headers = headers)