Xueqiu
a humanize XueQiu API wrappers.
Install / Use
/learn @1dot75cm/XueqiuREADME
xueqiu
a humanize XueQiu API wrappers.
Installation
1.First, you need to install some basic components.
2.And then, install Google Chrome Browser and Chrome Driver.
> copy chromedriver.exe %LOCALAPPDATA%\Programs\Python\Python37-32\
3.Finally, install xueqiu via pip.
$ pip install xueqiu # OR git+https://github.com/1dot75cm/xueqiu@master
$ pip install git+https://github.com/1dot75cm/browsercookie@master
$ python3 -m xueqiu
xueqiu x.y.z - A humanize XueQiu API wrappers.
:copyright: (c) 2019 by 1dot75cm.
:license: MIT, see LICENSE for more details.
enjoy!!!
Quick start
Example:
>>> news = xueqiu.news() # watch the news
>>> news
{'list': [<xueqiu.Post 为何价值投资长期有效[https://xueqiu.com/8291461932/120351059]>,
<xueqiu.Post 韬蕴资本CEO温晓东怒斥贾跃亭:怎就一个[https://xueqiu.com/2095268812/120483699]>,
<xueqiu.Post 增持与回购20190122-201901[https://xueqiu.com/9206540776/120458648]>,
<xueqiu.Post 医药研发外包为什么这么红?(上)[https://xueqiu.com/1472391509/120481662]>,
<xueqiu.Post 医药大赛道之大分子生物药(下)[https://xueqiu.com/1472391509/120482094]>,
<xueqiu.Post 增强型指数基金,到底“强”在哪里?[https://xueqiu.com/8082119199/120480761]>,
<xueqiu.Post 价值投资不需要概率思维吗?—与董宝珍先生[https://xueqiu.com/3555476733/120245234]>,
<xueqiu.Post 邓晓峰的投资观[https://xueqiu.com/7649503965/120430145]>,
<xueqiu.Post 复利无敌:买入一只股票看这四点[https://xueqiu.com/1876906471/120479202]>,
<xueqiu.Post 再论安全边际[https://xueqiu.com/4465952737/120453192]>],
'next_max_id': 20323343}
>>> p = news['list'][0]
>>> "{} {} 赞{} 评论{} 转发{} {}".format(p.title, p.user.name, p.like_count,
p.reply_count, p.retweet_count, p.target)
'为何价值投资长期有效 房杨凯的投资世界 赞9 评论11 转发9 https://xueqiu.com/8291461932/120351059'
>>> p.user.get_posts() # get user's article
>>> p.user.posts
{'count': 622,
'page': 1,
'maxpage': 63,
'list': [<xueqiu.Post [https://xueqiu.com/8291461932/120497097]>,
<xueqiu.Post [https://xueqiu.com/8291461932/120491351]>,
<xueqiu.Post [https://xueqiu.com/8291461932/120487476]>,
<xueqiu.Post [https://xueqiu.com/8291461932/120487448]>,
<xueqiu.Post [https://xueqiu.com/8291461932/120486037]>,
<xueqiu.Post 腾讯游戏帝国的护城河还在吗?[https://xueqiu.com/8291461932/120485596]>,
<xueqiu.Post [https://xueqiu.com/8291461932/120473933]>,
<xueqiu.Post [https://xueqiu.com/8291461932/120434054]>,
<xueqiu.Post [https://xueqiu.com/8291461932/120434037]>,
<xueqiu.Post [https://xueqiu.com/8291461932/120434020]>]}
>>> p.user.posts['list'][0].text # content
'回复@A8天道酬勤: 这个问题应该放在买之前。//@A8天道酬勤:回复@房杨凯的投资世界:假如花旗银行做假账,聂夫还会不会持有?'
>>> p.user.posts['list'][0].like() # like this (need login)
API
User class
A user class that contains user-related methods.
User object attributes:
id- user id.profile- user's profile url.name- user name.city- city, for example '上海'.description- user description.friends_count- the number of user's friends.followers_count- the number of user's fans.posts_count- the number of user's post.stocks_count- the number of stocks.friends- use to saveUserobject for friends.followers- use the saveUserobject for fans.posts- use the savePostobject for post.articles- use the savePostobject for user's article.favorites- use the savePostobject for favorite articles.stocks- use the saveStockobject for favorite stocks.hot_stocks- use the saveStockobject for the current hot stocks.
User object methods:
-
get_friends(page: int = 1)- get your friends and save toself.friends. -
get_followers(page: int = 1)- get your fans and save toself.followers. -
get_posts(page: int = 1, count: int = 10)- get your posts and save toself.posts. -
get_articles(page: int = 1, count: int = 10)- get your articles and save toself.articles. -
get_favorites(page: int = 1, count: int = 20)- get your favorite posts and save toself.favorites. -
get_stocks(mkt: int = 1, count: int = 1000)- get your stocks and save toself.stocks. -
get_hot_stocks(mkt: int = 10, time_range: str = "hour", count: int = 10)- get hottest stocks.- :param
mkt: (optional) market type, default is10.- value: 全球
10沪深12港股13美股11
- value: 全球
- :param
time_range: (optional) hottest stocks by time range, default ishour.- value:
hour,day
- value:
- :param
count: (optional) the number of results, default is10.
- :param
-
send_verification_code(phone: int)- send verification code to your phone. Note: only 5 times a day. -
login(uid: str = '', passwd: str = '', login_type: str = 'phone')- user login by password or verification code. If the cookie cache exists, load it first and return. Otherwise, login and save the cookie to file (Linux~/.xueqiu/cookieor Windows).- :param
uid: your username or phone number. - :param
passwd: your password or verification code. - :param
login_type: (optional) login type, default isphone.- value:
password,phone
- value:
- :param
-
load_cookie()- load cookies from local file or browser(chrome or firefox). You can login your account on the chrome browser, then executeload_cookie(), and now login successfully.
Example:
>>> u = User(2478797769)
>>> u.name
"红利基金"
>>> u.get_posts()
>>> u.posts['list'][0].title
'【你了解红利基金吗】红利基金(501029)热问快答!(12.31)'
>>> u.get_favorites()
>>> u.favorites['list'][0].title
'2018年A股大数据盘点:30张图尽览市场热点'
Post class
A post class that contains post-related methods.
Post object attributes:
id- post id.user- post authors. aUserclass object.created_at- created time. aArrowclass object.target- post url.view_count- view count.reply_count- reply count.retweet_count- retweet count.fav_count- favorites count.like_count- like count.title- post title.text- post content.full_text- the full content of the article.comments- use the saveCommentobject for post.
Post object methods:
get_content()- get article content and save toself.full_text.get_comments(page: int = 1, count: int = 20, asc: str = 'false')- get article comments and save toself.comments.like()- like the article. (require login)unlike()- unlike the article. (require login)favorite()- favorite the article. (require login)unfavorite()- unfavorite the article. (require login)
Example:
>>> p = Post('2478797769/78869335')
>>> p.user.name
"红利基金"
>>> p.created_at.format("YYYY-MM-DD")
"2016-12-13"
>>> p.title
'【你了解红利基金吗】红利基金(501029)热问快答!(12.31)'
>>> p.target
"https://xueqiu.com/2478797769/78869335"
>>> p.get_content()
>>> p.full_text
'目录:\n一、\n华宝标普中国A股红利机会指数证券投资基金\n......'
>>> p.get_comments()
>>> p.comments['list'][-1].text
'为什么成份股中有很多次新股?百思不得其解'
Comment class
A comment class that contains comment-related methods.
Comment object attributes:
id- comment id.user- comment authors. aUserclass object.post- comment on an article. aPostclass object.created_at- created time. aArrowclass object.like_count- like count.text- comment content.
Comment object methods:
like()- like the comment. (require login)unlike()- unlike the comment. (require login)
Example:
>>> p = Post('2478797769/78869335')
>>> p.get_comments()
>>> c = p.comments['list'][0]
>>> c.user.name
'红利基金'
>>> c.text
'回复@孙浩云: 怎么可能....2018年跌幅为24.54%,较主流指数跌幅较小。不知道您50%多是哪儿看来的呢'
Selector class
The Selector class implements a stock filter.
Selector object attributes:
market- market string, default isSH.- value:
SH,HK,US
- value:
queries- include default parameters with selector.
Selector object methods:
url()- return a selector url string.help(range: str = "base", show: str = "text")- show selector parameters.- :param
range: (optional) parameters range, default isbase. value:- SH: industries, areas, base, ball, quota, finan_rate, stock_data, profit_sheet, balance_sheet, cash_sheet
- HK: industries, base, ball, quota
- US: industries, base, ball, quota, grow, profit_sheet, balance_sheet, cash_sheet
- :param
show: (optional) output help or return generator, default istext.- value:
text,keys
- value:
- :param
scope(exchange: str = '', indcode: str = '', areacode: str = '')- set stock selector scope.- :param
exchange: (optional) set A-share exchange market, default isNone.- value:
SH,SZorNone
- value:
- :param
indcode: (optional) set industry code, default isNone. please seeself.help('industries') - :param
areacode: (optional) set area code, default isNone. please seeself.help('areas')
- :param
param(*args, **kwargs)- set stock selector paramters.- :param
*args: (optional) set parameters key, default value isALL. for example, theself.param('pb', 'mc')will be setpb=ALL&mc=ALLparams. - :param
**kwargs: (optional) set parameters key and value. for example, theself.param('pettm'=0_30)will be setpettm=0_30param.
- :param
orderby(key: str = 'symbol')- stock selector results are sorted by field.- :param
key: the results are sorted by thekey, default issymbol. the key parameters can be viewed throughself.help('base').
- :param
order(ord: str = 'desc')- set stock selector results are sorted.- :param
ord: the ascending and descending order, default isdesc.- value:
asc,desc
- value:
- :param
page(page: int = 1)- set stock selector results page number.count(size: int = 10)- the number of stock selector results.run()- sends a stoc
Related Skills
node-connect
352.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
352.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
352.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
