In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to use Python to crawl stock data, many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
Basic environment configuration
Python 3.6
Pycharm
Requests
Csv
Time
The related module pip can be installed.
Target web page
Find the data, directly request the web page, parse the data, save the data
Request web page import requestsurl = 'https://xueqiu.com/service/v5/stock/screener/quote/list'response = requests.get (url=url, params=params, headers=headers) Cookies=cookies) html_data = response.json () parsing data data_list = html_data ['data'] [' list'] for i in data_list: dit = {} dit ['stock symbol'] = I ['symbol'] dit [' stock name'] = I ['name'] dit [' current price'] = I ['current'] dit [' up and down'] = I ['chg'] dit [' /%'] = I ['percent'] dit [' year to date /%'] = I ['current_year_percent'] dit [' turnover'] = I ['volume'] dit [' turnover'] = I ['amount'] dit [' turnover /%'] = I ['turnover_rate'] dit [' price-to-earnings ratio TTM'] = I ['pe_ttm'] dit [' dividend Rate /%'] = I ['dividend_yield'] dit [' market capitalization'] = I ['market_capital'] print (dit)
Save data import csvf = open ('stock data .csv', mode='a', encoding='utf-8-sig', newline='') csv_writer = csv.DictWriter (f, fieldnames= ['stock symbol', 'stock name', 'current price','up and down amount','up and down /%', 'year to date /%', 'volume', 'turnover', 'turnover /%','P / E TTM'' 'dividend yield /%', 'market capitalization'] csv_writer.writeheader () csv_writer.writerow (dit) f.close () read the above content Do you know more about how to crawl stock data using Python? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.