爬虫游戏 基础2 http://glidedsky.com

# -*- coding:utf-8 -*-
import re
import requests

def extract_sums():
    url ='http://glidedsky.com/login'

    h = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36",
    }
    session = requests.session()
    session.headers = h
    token = session.get(url)
    _token = re.search(r'"_token" value="(.*?)"',token.text).group(1)
    print(_token)
    data = {
        "_token": _token,
        "email": "邮箱",
        "password": "密码",
    }
    session.post(url,data=data,)

    sum_number = 0

    for i in range(1,1001):
        res2 = session.get(f'http://glidedsky.com/level/web/crawler-basic-2?page={i}')
        html = re.search(r'
(.*)class="pagination"',res2.text,re.S) nums = re.findall(r'\d{3}',html.group(1)) sum_number += sum([int(i) for i in nums]) print(i,len(nums),sum_number) return sum_number print('结果:',extract_sums())

 

你可能感兴趣的:(Python)