爬取雪球新闻。

三页房产信息这里写代码片

import json
from urllib import request
import pymysql
db = pymysql.connect(host='127.0.0.1', user='root', password='123456', port=3306, database='xueqiu')
cursor = db.cursor()
b=-1
i=0
while i<4:
    url= 'https://xueqiu.com/v4/statuses/public_timeline_by_category.json?since_id=-1&max_id='+str(b)+'&count=10&category=111'
    headers = {
    # "Accept":"*/*",
    # "Accept-Encoding":"gzip, deflate, br",
    # "Accept-Language":"zh-CN,zh;q=0.9",
    # "Connection":"keep-alive",
    "Cookie":"aliyungf_tc=AQAAAPXkYR9BPQEAUhVFeeJ4XevzmLTD; xq_a_token=584d0cf8d5a5a9809761f2244d8d272bac729ed4; xq_a_token.sig=x0gT9jm6qnwd-ddLu66T3A8KiVA; xq_r_token=98f278457fc4e1e5eb0846e36a7296e642b8138a; xq_r_token.sig=2Uxv_DgYTcCjz7qx4j570JpNHIs; u=921534296001764; _ga=GA1.2.1552424872.1534296003; _gid=GA1.2.103419721.1534296003; device_id=f1ac0af13982a3a324393d8b29c39b20; Hm_lvt_1db88642e346389874251b5a1eded6e3=1534296003,1534296229; Hm_lpvt_1db88642e346389874251b5a1eded6e3=1534296229",
    # "Host":"xueqiu.com",
    # "Referer":"https://xueqiu.com/",
    "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.26 Safari/537.36 Core/1.63.5702.400 QQBrowser/10.2.1893.400",
    # "X-Requested-With":"XMLHttpRequest",
    }
    req = request.Request(url,headers=headers)
    response = request.urlopen(req)
    html = json.loads(response.read().decode('utf-8'))
    html_list=html['list']
    for list_data in html_list:
        data = list_data['data']
        data = json.loads(data)
        # print(type(data))
        id = data['id']
        id = str(id)
        title = data['title']
        description = data['description']
        target = data['target']
        sql = "insert into xueqiu(id,title,description,target) values('"+id+"','"+title+"','"+description+"','"+target+"')"
        cursor.execute(sql)
        db.commit()
    b = html['next_max_id']
    i=i+1
    if i >=4:
        break
cursor.close()
db.close()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值