题主会计学二专毕业设计论文DDL在即,做的是分析食品企业会计信息与股价的实证课题,目前需要从新浪财经上收集100家食品企业近五年的财报,如果手动收集的话是根据证监会2014年4季度上市公司行业分类结果上的上市公司股票代码输到股票首页_新浪财经 的搜索框,然后再从所选公司的网页(如康达尔(000048)股票股价,行情,新闻,财报数据)上点选“公司年报”,下载近五年的年报数据。
所选企业是2014年4季度上市公司行业分类结果上所有13、14、15大类,有100多家,全部手动收集的话工作量略大,想问下有没有办法用Python写一个脚本完成以上工作?(大学修过一门用python讲的计算思维,算是有一点点python基础吧)
感激不尽~
提问后一周已经搞定了,用了excel power query+yahoo finance api 等这周忙完毕业设计回来更新问题…还是非常感谢~!就当练手了~问题的解决办法有很多。利用现有的api挺方便。不过我还是按照题主原来的思路笨办法写写试试。
<code class="language-python"><span class="n">f</span><span class="o">=</span><span class="nb">open</span><span class="p">(</span><span class="s">'stock_num.txt'</span><span class="p">)</span> <span class="n">stock</span> <span class="o">=</span> <span class="p">[]</span> <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="o">.</span><span class="n">readlines</span><span class="p">():</span> <span class="c">#print(line,end = '')</span> <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">'</span><span class="se">\n</span><span class="s">'</span><span class="p">,</span><span class="s">''</span><span class="p">)</span> <span class="n">stock</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">line</span><span class="p">)</span> <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> <span class="k">print</span><span class="p">(</span><span class="n">stock</span><span class="p">)</span> </code>
<code class="language-python"><span class="k">def</span> <span class="nf">xml_Error_C</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span> <span class="n">fp_xml</span><span class="o">=</span><span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span> <span class="n">fp_x</span><span class="o">=</span><span class="s">''</span><span class="c">#中文乱码改正</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">getsize</span><span class="p">(</span><span class="n">filename</span><span class="p">)):</span> <span class="n">i</span><span class="o">+=</span><span class="mi">1</span> <span class="n">a</span><span class="o">=</span><span class="n">fp_xml</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="k">if</span> <span class="n">a</span><span class="o">==</span><span class="s">'&'</span><span class="p">:</span> <span class="n">fp_xml</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span> <span class="k">if</span> <span class="n">fp_xml</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">6</span><span class="p">)</span><span class="o">==</span><span class="s">' '</span><span class="p">:</span> <span class="n">i</span><span class="o">+=</span><span class="mi">5</span> <span class="k">continue</span> <span class="k">else</span><span class="p">:</span> <span class="n">fp_xml</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span> <span class="n">fp_x</span><span class="o">+=</span><span class="n">a</span> <span class="n">fp_xml</span><span class="o">=</span><span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span><span class="s">'w+'</span><span class="p">)</span> <span class="n">fp_xml</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">fp_x</span><span class="p">)</span> <span class="n">fp_xml</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span> <span class="n">fp_xml</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> </code>