爬取雪球网 泸深股市 代码

import requests
import json
import math

url = 'https://xueqiu.com/service/v5/stock/screener/quote/list'

headers = {
    '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'
}

params = {
    'page': '1',
    'size': '30',
    'order': 'desc',
    'orderby': 'percent',
    'order_by': 'percent',
    'market': 'HK',
    'type': 'hk',
    '_': '1566213291032'
}

def send_request():
    response = requests.get(url=url,headers=headers,params=params)
    print(response.url)
    print(response.status_code)
    if response.status_code == 200:
        return response

def paese_data(response):
    print(response.text)
    data = json.loads(response.text)

    list = data.get('data').get('list')
    for i in list:
        print(i)

if __name__ == '__main__':
    response = requests.get(
        url=url,
        headers=headers,
        params=params
    )
    if response.status_code == 200:
        print('请求成功')
        print(response.text)
        data = json.loads(response.text)

        page_data = data.get('data')
        page_num = math.ceil(page_data.get('count')/30)

        for p in range(1,page_num + 1):
            print(p)
            data['page'] = str(p)
            response = send_request()
            paese_data(response)

你可能感兴趣的:(爬取雪球网 泸深股市 代码)