コード例 #1
0
def get_text(tartget, host='.xueqiu.com'):
    base = 'https://xueqiu.com'
    url = base + str(tartget)
    s = requests.Session()
    r = s.get(url, cookies=gcookies(host), headers=hds())
    html = lxml.html.parse(StringIO(r.text))
    xc = html.xpath('//article/div/p//text()')
    text = '\n'.join(xc)
    return text
コード例 #2
0
def hotline_xueqiu(host='.xueqiu.com'):
    hurl = 'https://xueqiu.com/v4/statuses/public_timeline_by_category.json?since_id=-1&max_id=-1&count=10&category=-1'
    s = requests.Session()
    r = s.get(hurl, cookies=gcookies(host), headers=hds())
    data = json.loads(r.text)
    exlist = []
    exlist.extend(_hotline(data))
    nmid = data['next_max_id']
    go = 1
    url = 'https://xueqiu.com/v4/statuses/public_timeline_by_category.json?since_id=-1&max_id={0}&count=15&category=-1'.format(
        nmid)
    for i in range(nmid, 0, -15):
        r = s.get(hurl, cookies=gcookies(host), headers=hds())
        dataI = json.loads(r.text)
        exlist.extend(_hotline(dataI))
        go = go + 1
        if go > 20:
            break

    return exlist
コード例 #3
0
def get_kdata_xueqiu(code,
                     begin=None,
                     ktype='day',
                     fq='N',
                     host='.xueqiu.com'):
    """
    code:
    """

    if (code[0] in ['0', '2', '3', '6', '9']) and len(code) == 6:
        if code[0] in ['6', '9']:
            code = 'SH' + code
        elif code[0] in ['0', '2', '3']:
            code = 'SZ' + code
        else:
            sys.exit()

    s = requests.Session()
    kline = {
        'day': 'day',
        'week': 'week',
        'month': 'month',
        'quarter': 'quarter',
        '120m': '120m',
        '60m': '60m',
        '30m': '30m',
        '15m': '15m',
        '5m': '5m',
        '1m': '1m'
    }
    fqtype = {'qfq': 'before', 'N': 'normal', 'hfq': 'after'}

    if begin == None:
        begin = datetime.datetime.now()
        begin = int(time.mktime(begin.timetuple()) * 1000)
    else:
        begin = mk.str2timestamp(begin) * 1000

    url = 'https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol={0}&begin={1}&period={2}&type={3}&count=-3260&indicator=kline,ma,macd,kdj,boll,rsi,wr,bias,cci,psy'.format(
        code, begin, kline[ktype], fqtype[fq])
    r = s.get(url, cookies=gcookies(host), headers=hds())
    data = json.loads(r.text)
    df = pd.DataFrame(data['data']['item'])
    df.columns = data['data']['column']
    df['timestamp'] = df['timestamp'].map(
        lambda x: mk.timestamp2str(x, mtype='t'))
    df = df.dropna(axis=1, how='all')
    df = df.set_index('timestamp')
    return df
コード例 #4
0
def get_dadan_xueqiu(code, host='.xueqiu.com'):

    if (code[0] in ['0', '2', '3', '6', '9']) and len(code) == 6:
        if code[0] in ['6', '9']:
            code = 'SH' + code
        elif code[0] in ['0', '2', '3']:
            code = 'SZ' + code
        else:
            sys.exit()

    s = requests.Session()

    url = 'https://xueqiu.com/stock/forchart/stocklist.json?symbol={0}&period=1d&one_min=1'.format(
        code)
    r = s.get(url, cookies=gcookies(host), headers=hds())
    data = json.loads(r.text)
    df = pd.DataFrame(data['chartlist'])
    df = df.dropna(axis=1)
    df['timestamp'] = df['timestamp'].map(
        lambda x: mk.timestamp2str(x, mtype='t'))
    return df
コード例 #5
0
def get_kdata_xueqiuv(code,
                      begin=None,
                      end=None,
                      ktype='day',
                      fq='N',
                      host='.xueqiu.com'):

    if (code[0] in ['0', '2', '3', '6', '9']) and len(code) == 6:
        if code[0] in ['6', '9']:
            code = 'SH' + code
        elif code[0] in ['0', '2', '3']:
            code = 'SZ' + code
        else:
            sys.exit()

    s = requests.Session()
    kline = {'day': '1day', 'week': '1week', 'month': '1month'}
    fqtype = {'qfq': 'before', 'N': 'normal'}

    if end == None:
        end = int(time.time() * 1000)
    else:
        end = mk.str2timestamp(end) * 1000
    if begin == None:
        begin = datetime.datetime.now() - datetime.timedelta(days=360 * 3)
        begin = int(time.mktime(begin.timetuple()) * 1000)
    else:
        begin = mk.str2timestamp(begin) * 1000

    url = 'https://xueqiu.com/stock/forchartk/stocklist.json?symbol={0}&period={1}&type={2}&begin={3}&end={4}'.format(
        code, kline[ktype], fqtype[fq], begin, end)
    r = s.get(url, cookies=gcookies(host), headers=hds())
    data = json.loads(r.text)
    df = pd.DataFrame(data['chartlist'])
    df['timestamp'] = df['timestamp'].map(
        lambda x: mk.timestamp2str(x, mtype='t'))
    df = df.dropna(axis=1, how='all')
    df = df.set_index('timestamp')
    df = df.drop('time', axis=1)
    return df
コード例 #6
0
def get_searchjson_xueqiu(code, host='.xueqiu.com', lp=10):
    if code[0] in ['6', '9']:
        code = 'SH' + code
    elif code[0] in ['0', '2', '3']:
        code = 'SZ' + code
    else:
        sys.exit()

    exlist = []
    s = requests.Session()
    for i in range(lp + 1):
        url = 'https://xueqiu.com/statuses/search.json?count=10&comment=0&symbol={0}&hl=0&source=all&sort=time&page={1}&q='.format(
            code, i)
        r = s.get(url, cookies=gcookies(host), headers=hds())
        data = json.loads(r.text)
        for txs in data['list']:
            text = txs['text']
            dtext = lxml.html.parse(StringIO(text))
            dtem = dtext.xpath('//p/text()')
            if len(dtem) > 0:
                exlist.append(dtem)

    return exlist
コード例 #7
0
def finance_xueqiu(code, host='.xueqiu.com'):
    if code[0] in ['6', '9']:
        code = 'SH' + code
    elif code[0] in ['0', '2', '3']:
        code = 'SZ' + code
    else:
        sys.exit()

    exlist = []
    s = requests.Session()
    url = 'https://xueqiu.com/stock/f10/finmainindex.json?symbol={0}&page=1&size=60'.format(
        code)

    r = s.get(url, cookies=gcookies(host), headers=hds())
    data = json.loads(r.text)
    df = pd.DataFrame(data['list'])
    df = df.set_index('reportdate')
    df.index = pd.to_datetime(df.index)
    df['symbol'] = code
    df = df.where(df.notnull(), np.nan)
    df = df.drop(['compcode', 'name'], axis=1)
    df = df.dropna(axis=1, how='all')
    return df