美文网首页
爬取雪球网 泸深股市 代码

爬取雪球网 泸深股市 代码

作者: 姓高名旭升 | 来源:发表于2019-08-19 20:12 被阅读0次
    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)
    

    相关文章

      网友评论

          本文标题:爬取雪球网 泸深股市 代码

          本文链接:https://www.haomeiwen.com/subject/xooesctx.html