id: 8620417d81a741cdbca2fc730c534143
parent_id: 
item_type: 1
item_id: 7f3eb9a8499a4f1da660214291a25754
item_updated_time: 1764345627259
title_diff: "[{\"diffs\":[[1,\"【Python技术】抓取同花顺财务数据\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":19}]"
body_diff: "[{\"diffs\":[[1,\"<html>\\\r\\\n<head>\\\r\\\n  <title>【Python技术】抓取同花顺财务数据</title>\\\r\\\n  <basefont face=\\\"微软雅黑\\\" size=\\\"2\\\" />\\\r\\\n  <meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html;charset=utf-8\\\" />\\\r\\\n  <meta name=\\\"exporter-version\\\" content=\\\"YXBJ Windows/608924 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;\\\"/>\\\r\\\n  <meta name=\\\"content-class\\\" content=\\\"yinxiang.peso.superNote\\\"/>\\\r\\\n  <meta name=\\\"application-data:yinxiang.noteLayout\\\" content=\\\"{\\\"lineSpace\\\":\\\"recommend\\\",\\\"paragraphSpace\\\":\\\"recommend\\\"}\\\"/>\\\r\\\n  <style>\\\r\\\n\\tbody, td {\\\r\\\n\\t  font-family: 微软雅黑;\\\r\\\n\\t  font-size: 12pt;\\\r\\\n\\t}\\\r\\\n  </style>\\\r\\\n</head>\\\r\\\n<body>\\\r\\\n<a name=\\\"39768\\\"></a>\\\r\\\n<h1>【Python技术】抓取同花顺财务数据</h1>\\\r\\\n\\\r\\\n<div><span style=\\\"\\\"><div style=\\\"max-width: 700px;\\\"><p></p><div style=\\\"--en-blockquote: true; box-sizing: border-box; border-left: 3px solid #b4c0cc; background-position: initial initial; background-repeat: initial initial;\\\"><div>原文链接: <a href=\\\"http://mp.weixin.qq.com/s?__biz=MzI5NDAzNzExNw==&amp;mid=2247487244&amp;idx=1&amp;sn=96dc7ed6cac461d3b87eaa683b2eb4c0&amp;chksm=ede5db30258af7d57b0131e90aeae882b51f57eb03bcb6f78637dff3de70f7a599d42ef89f3e&amp;mpshare=1&amp;scene=1&amp;srcid=0411lzzbsjVBxja4FiseYml6&amp;sharer_shareinfo=c4f6a1d8e28953565b1f0a120971f9d5&amp;sharer_shareinfo_first=c4f6a1d8e28953565b1f0a120971f9d5#rd\\\"><span>http://mp.weixin.qq.com/s?__biz=MzI5NDAzNzExNw==&amp;mid=2247487...</span></a></div></div><p></p><div style=\\\"\\\"><div><div><div><span style=\\\"\\\">原创</span><span><span style=\\\"\\\">子晓0808</span></span><span><a style=\\\"\\\"> 子晓聊技术 </a></span><span><em></em></span></div><div style=\\\"\\\"><div style=\\\"text-align: center;\\\"><img src=\\\":/9bfb2cee13c24ff0b5b8711baccec606\\\" type=\\\"image/png\\\" data-filename=\\\"640.png\\\" style=\\\"--en-marks: %7B%22align%22%3A%22center%22%7D; width: auto;\\\" width=\\\"auto\\\"/></div><div><span><br/></span></div><div><span>背景：星球同学和我说怎么抓取同花顺的财务数据， 我当时一想akshare不是有业绩这玩意么， 后来看了下 那是抓取东方财富的。  同花顺的方法其实可以仿照akshare自己封装一个方法就好了。</span></div><div><span>现在4月份了，一年一度的业绩快报在披露了，另外25年的一季度业绩预告也在披露。 我们在炒股的时候一定要注意业绩雷。</span></div><div><span>如果碰到东方集团、汇金科技等这种财务造假、业绩暴雷， 想哭都没地方去。</span></div><h1 style=\\\"\\\"><span style=\\\"color: rgba(0, 0, 0, 0.9); letter-spacing: 0.034em; font-style: normal; font-weight: normal;\\\">我们要善于利用股票F10进行投资分析， 实在不会分析。 像DeepSeek这样的AI工具总会吧，把这些信息提供给AI，让AI分析下财务状况也可以。毕竟有了AI， 基本面财务分析是不是变得非常简单了。</span></h1><div><span><br/></span></div><div><span>相关文章推荐：</span></div><div><span><a href=\\\"https://mp.weixin.qq.com/s?__biz=MzI5NDAzNzExNw==&amp;mid=2247484457&amp;idx=1&amp;sn=a80a4a487edef93853038db7a42a59e0&amp;scene=21#wechat_redirect\\\" style=\\\"\\\" target=\\\"_blank\\\">【python技术】akshare爬取A股最新业绩预告保存进excel的简单示例</a></span></div><div><span><br/></span></div><div><span><span style=\\\"font-weight: bold;\\\">题外话：</span></span></div><div><span>相比业绩雷， 特朗普发起的MY战更是黑天鹅， 看着架势会越演越烈。  昨天晚上看着纳斯达克一度涨了4个多点，一觉醒来， 纳斯达克跌了2个多点。虽然我没买，最高一来一去就6个点财富就这样蒸发了。  昨天晚上睡前还在想，我今天是要抄底还是谨慎呢， 看这样的态势发展， 还是谨慎一点，</span><span>君子不立危墙之下。 我赶紧看了看2008年 和2018年的K线图，趁着间隙，要不看看毛爷爷的毛选《论持久战》。</span></div><div><span>有些时候，发觉自己就没有发财命。  4.3的时候，就发现了 养殖 、 国内消费、稀土等的投资机会， 为了防止清明节假期突发幺蛾子， 还是没敢买看着涨起来的养殖，如果当时买了40个点有了吧。 还是赚不到认知外的钱。</span></div><div><span><br/></span></div><div style=\\\"background-attachment: scroll; background-clip: border-box; background-color: rgba(0, 0, 0, 0); background-image: none; background-origin: padding-box; background-position-x: 0%; background-position-y: 0%; background-repeat: no-repeat; background-size: auto; width: auto; color: rgb(0, 0, 0); word-spacing: 0em; letter-spacing: 0em; word-break: break-word; overflow-wrap: break-word; text-align: left;\\\"><div style=\\\"border-radius: 5px; text-align: left;\\\"><div style=\\\"--en-codeblock: true; --en-meta: {&quot;title&quot;:&quot;&quot;,&quot;lang&quot;:&quot;Plain Text&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;showLine&quot;:true,&quot;lineWrap&quot;:true}; box-sizing: border-box; color: rgb(51, 51, 51); border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom-right-radius: 4px; border-bottom-left-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.14902); background-position: initial initial; background-repeat: initial initial;\\\"><pre><span>from io import StringIO</span><br/><span></span><br/><span>import pandas as pd</span><br/><span>import requests</span><br/><span>from bs4 import BeautifulSoup</span><br/><span>import py_mini_racer</span><br/><span>from akshare.utils.tqdm import get_tqdm</span><br/><span></span><br/><span>from akshare.datasets import get_ths_js</span><br/><span></span><br/><span># Setting up pandas display options</span><br/><span>pd.set_option('display.unicode.ambiguous_as_wide', True)</span><br/><span>pd.set_option('display.unicode.east_asian_width', True)</span><br/><span>pd.set_option('display.max_rows', None)</span><br/><span>pd.set_option('display.max_columns', None)</span><br/><span>pd.set_option('display.expand_frame_repr', False)</span><br/><span>pd.set_option('display.max_colwidth', 100)</span><br/><span></span><br/><span>def _get_file_content_ths(file: str = &quot;ths.js&quot;) -&gt; str:</span><br/><span>    &quot;&quot;&quot;</span><br/><span>    获取 JS 文件的内容</span><br/><span>    :param file:  JS 文件名</span><br/><span>    :type file: str</span><br/><span>    :return: 文件内容</span><br/><span>    :rtype: str</span><br/><span>    &quot;&quot;&quot;</span><br/><span>    setting_file_path = get_ths_js(file)</span><br/><span>    with open(setting_file_path, encoding=&quot;utf-8&quot;) as f:</span><br/><span>        file_data = f.read()</span><br/><span>    return file_data</span><br/><span></span><br/><span></span><br/><span>def getYeji(symbol: str = &quot;业绩快报&quot;, type: str = &quot;2024-12-31&quot;):</span><br/><span>    js_code = py_mini_racer.MiniRacer()</span><br/><span>    js_content = _get_file_content_ths(&quot;ths.js&quot;)</span><br/><span>    js_code.eval(js_content)</span><br/><span>    v_code = js_code.call(&quot;v&quot;)</span><br/><span>    headers = {</span><br/><span>        &quot;Accept&quot;: &quot;text/html, */*; q=0.01&quot;,</span><br/><span>        &quot;Accept-Encoding&quot;: &quot;gzip, deflate&quot;,</span><br/><span>        &quot;Accept-Language&quot;: &quot;zh-CN,zh;q=0.9,en;q=0.8&quot;,</span><br/><span>        &quot;Cache-Control&quot;: &quot;no-cache&quot;,</span><br/><span>        &quot;Connection&quot;: &quot;keep-alive&quot;,</span><br/><span>        &quot;hexin-v&quot;: v_code,</span><br/><span>        &quot;Host&quot;: &quot;data.10jqka.com.cn&quot;,</span><br/><span>        &quot;Pragma&quot;: &quot;no-cache&quot;,</span><br/><span>        &quot;Referer&quot;: &quot;http://data.10jqka.com.cn/funds/hyzjl/&quot;,</span><br/><span>        &quot;User-Agent&quot;: &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) &quot;</span><br/><span>                      &quot;Chrome/90.0.4430.85 Safari/537.36&quot;,</span><br/><span>        &quot;X-Requested-With&quot;: &quot;XMLHttpRequest&quot;,</span><br/><span>    }</span><br/><span>    url = &quot;http://data.10jqka.com.cn/funds/ggzjl/field/code/order/desc/ajax/1/free/1/&quot;</span><br/><span>    r = requests.get(url, headers=headers)</span><br/><span>    soup = BeautifulSoup(r.text, features=&quot;lxml&quot;)</span><br/><span>    raw_page = soup.find(name=&quot;span&quot;, attrs={&quot;class&quot;: &quot;page_info&quot;}).text</span><br/><span>    page_num = raw_page.split(&quot;/&quot;)[1]</span><br/><span>    if symbol == &quot;业绩预告&quot;:</span><br/><span>        url = &quot;https://data.10jqka.com.cn/ajax/yjyg/date/&quot;+type+&quot;/board/YJYZ/field/enddate/ajax/1/free/1/&quot;</span><br/><span>    if symbol == &quot;业绩快报&quot;:</span><br/><span>        url =&quot;https://data.10jqka.com.cn/ajax/yjkb/date/&quot;+type+&quot;/board/HSAG/field/declaredate/ajax/1/free/1/&quot;</span><br/><span>    big_df = pd.DataFrame()</span><br/><span>    tqdm = get_tqdm()</span><br/><span>    for page in tqdm(range(1, int(page_num) + 1), leave=False):</span><br/><span>        js_code = py_mini_racer.MiniRacer()</span><br/><span>        js_content = _get_file_content_ths(&quot;ths.js&quot;)</span><br/><span>        js_code.eval(js_content)</span><br/><span>        v_code = js_code.call(&quot;v&quot;)</span><br/><span>        headers = {</span><br/><span>            &quot;Accept&quot;: &quot;text/html, */*; q=0.01&quot;,</span><br/><span>            &quot;Accept-Encoding&quot;: &quot;gzip, deflate&quot;,</span><br/><span>            &quot;Accept-Language&quot;: &quot;zh-CN,zh;q=0.9,en;q=0.8&quot;,</span><br/><span>            &quot;Cache-Control&quot;: &quot;no-cache&quot;,</span><br/><span>            &quot;Connection&quot;: &quot;keep-alive&quot;,</span><br/><span>            &quot;hexin-v&quot;: v_code,</span><br/><span>            &quot;Host&quot;: &quot;data.10jqka.com.cn&quot;,</span><br/><span>            &quot;Pragma&quot;: &quot;no-cache&quot;,</span><br/><span>            &quot;Referer&quot;: &quot;http://data.10jqka.com.cn/funds/hyzjl/&quot;,</span><br/><span>            &quot;User-Agent&quot;: &quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) &quot;</span><br/><span>                          &quot;Chrome/90.0.4430.85 Safari/537.36&quot;,</span><br/><span>            &quot;X-Requested-With&quot;: &quot;XMLHttpRequest&quot;,</span><br/><span>        }</span><br/><span>        r = requests.get(url.format(page), headers=headers)</span><br/><span>        temp_df = pd.read_html(StringIO(r.text))[0]</span><br/><span>        big_df = pd.concat(objs=[big_df, temp_df], ignore_index=True)</span><br/><span>        return big_df</span><br/><span></span><br/><span></span><br/><span>#print(getYeji(&quot;业绩预告&quot;, &quot;2025-03-31&quot;))</span><br/><span>print(getYeji(&quot;业绩快报&quot;, &quot;2024-12-31&quot;))</span><br/><span></span><br/></pre></div></div></div><div><span><br/></span></div><div><span><br/></span></div><div><span><br/></span></div><div><span><br/></span></div><div><span><br/></span></div></div></div></div></div></div></span>\\\n</div></body></html>\\u0000\"]],\"start1\":0,\"start2\":0,\"length1\":0,\"length2\":9959}]"
metadata_diff: {"new":{"id":"7f3eb9a8499a4f1da660214291a25754","parent_id":"f67288c3a0be4374b5d532b5dcc3aabc","latitude":"0.00000000","longitude":"0.00000000","altitude":"0.0000","author":"","source_url":"","is_todo":0,"todo_due":0,"todo_completed":0,"source":"joplin-desktop","source_application":"net.cozic.joplin-desktop","application_data":"","order":1764348829017,"markup_language":2,"is_shared":0,"share_id":"","conflict_original_id":"","master_key_id":"","user_data":"","deleted_time":0},"deleted":[]}
encryption_cipher_text: 
encryption_applied: 0
updated_time: 2025-11-28T21:04:04.099Z
created_time: 2025-11-28T21:04:04.099Z
type_: 13