How can I use Python to write a script to capture the annual report of a specified enterprise on Sina finance and economics network?

Source: Internet
Author: User
Tags excel power
Subject: DDL is coming soon. It is an empirical study on the accounting information and stock price of food companies, at present, we need to collect financial reports from 100 food companies from Sina financial for nearly five years, if you manually collect the information, the stock code of the listed company on the result of the listed company category of the China Securities Regulatory Commission in the fourth quarter of 2014 will be sent to the search box of Sina finance, then, click "company annual report" on the webpage of the selected company (such as kangdal (000048) stock price, quotations, news, and financial report data) to download the annual report data for the past five years. The selected enterprise is the subject of the fourth quarter of 2014. The DDL is just around the corner. It is an empirical study on the accounting information and stock price of food enterprises, at present, we need to collect financial reports of 100 food companies from Sina financial for the last five years. If we need to collect financial reports manually, it is based on the industry classification results of listed companies by the China Securities Regulatory Commission in the fourth quarter of 2014. The stock code of a listed company is sent to the stock homepage _ Sina finance The search box, and then from the page of the selected company (such as kangdal (000048) stock price, quotations, news, financial report data Click "company annual report" to download the annual report data for the last five years.
The selected enterprise is the result of the industry classification of listed companies in the fourth quarter of 2014. There are more than 100 of the top 13, 14, and 15 categories. If all of them are collected manually, the workload is a little large. Can you write a script in Python to complete the above work? (If you have learned a lot about computing thinking in python, you have a little python basics)
Grateful ~ Reply content: Hi ~ I have answered the question ~
Although the subject has fixed the problem ......
I have fixed the problem one week later. I used excel power query + yahoo finance api to update the problem after I finished my graduation project this week... Thank you very much ~!
It's just a matter of practice ~ There are many solutions to the problem. It is convenient to use existing APIs. However, I still try to write in a stupid way based on the original ideas of the subject.
Old Rules, while making adjustments and writing ~
# A newbie is very stupid. Please don't try it.
# Start coding
The first step is to collect stock code... Copy and paste the three types of stock code 13, 14, and 15 into a text document using the online ipv2doc website. Like this...
Then we need to let Python read the content in the text document by line and store it into a list. Very simple. Then we need to let Python read the content in the text document by line and store it into a list. Very simple.

f=open('stock_num.txt')stock = []for line in f.readlines():    #print(line,end = '')    line = line.replace('\n','')    stock.append(line)f.close()print(stock)
With the selenium module, you can write a program to simulate the entire process of manually clicking the button.
It feels like writing a button.
Just sauce. How scrapy works with chrome or firefox in minutes We recommend that you use Dongfang fortune network to capture data because it can be saved as an excel document directly.The post-processing is also relatively convenient. The idea is as follows:
1. first obtain the stock code and name of the desired listed company. For this step, refer to @ Duan xiaochen's answer!
2. Analyze the download link. Take kangdal as an example, the annual report address http://soft-f9.eastmoney.com/soft/gp14.php? Code = 00004802 To download the eastmoney.com page. The first six digits at the end of the link are the stock code, the last two 01 representing listed companies on the Shanghai Stock Exchange (the stock code starts with 60), and 02 representing listed companies on the Shenzhen Stock Exchange. You can use a loop to download all the data!
3. Convert the downloaded xml file into an xls file. The Code is as follows:
1) possible Chinese Encoding Error Handling in. xml

Def xml_Error_C (filename): fp_xml = open (filename) fp_x = ''# Chinese garbled correction for I in range (OS. path. getsize (filename): I + = 1 a = fp_xml.read (1) if a = '&': fp_xml.seek (-1, 1) if fp_xml.read (6) = '': I + = 5 continue else: fp_xml.seek (-5, 1) fp_x + = a fp_xml = open (filename, 'W + ') fp_xml.write (fp_x) fp_xml.flush () fp_xml.close ()
You can use the arrow to search for crawlers on the cloud. Writing fast, and comes with data export release and generation of charts for data analysis, big data era weapon AH ( ̄) "with tushare, http://tushare.waditu.com Use scrapy to write a crawler that crawls resources quickly! If you want to download "annual report data" instead of "Annual Report", use the excel plug-in of wind to pull the function. If you want to download the "Annual Report data", you can just pull the function... My major in accounting indicates that the school must have a business school, and a business school must have a wind terminal... Go to the school data center for half an hour...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.