tigercitytaiwan / 20240208

20240208
0 stars 0 forks source link

20240601 #3

Open tigercitytaiwan opened 3 months ago

tigercitytaiwan commented 3 months ago

要在Linux上实现每天收盘后自动用Python截取网站的最新收盘行情,可以按照以下步骤进行:

  1. 安装必要的软件和库

    • 确保你有Python和pip安装在系统上。
    • 安装所需的Python库,如requestsBeautifulSoup用于网页抓取,schedule用于任务调度。
    sudo apt-get update
    sudo apt-get install python3 python3-pip
    pip3 install requests beautifulsoup4 schedule
  2. 编写Python脚本: 创建一个Python脚本,例如stock_scraper.py,该脚本将负责从网站抓取收盘行情。

    import requests
    from bs4 import BeautifulSoup
    import datetime
    
    def scrape_stock_data():
       # 替换为实际的股票行情网站URL
       url = 'https://example.com/stock-data'
       response = requests.get(url)
       soup = BeautifulSoup(response.text, 'html.parser')
    
       # 假设你需要抓取的行情在某个特定的HTML标签内
       # 具体标签和属性需要根据实际网站调整
       data = {
           'dow_jones': soup.find('div', {'id': 'dow_jones'}).text,
           's_and_p_500': soup.find('div', {'id': 's_and_p_500'}).text,
           'nasdaq': soup.find('div', {'id': 'nasdaq'}).text,
           'phlx_semiconductor': soup.find('div', {'id': 'phlx_semiconductor'}).text
       }
    
       # 保存到文件
       filename = f"stock_data_{datetime.datetime.now().strftime('%Y-%m-%d')}.txt"
       with open(filename, 'w') as file:
           for key, value in data.items():
               file.write(f"{key}: {value}\n")
    
    if __name__ == '__main__':
       scrape_stock_data()
  3. 使用cron调度任务: 使用cron来每天定时运行该脚本。首先编辑crontab:

    crontab -e

    在crontab文件中添加以下行,设置脚本在每天收盘后运行(例如,美国东部时间每天16:30运行,即UTC时间20:30):

    30 20 * * * /usr/bin/python3 /path/to/your/stock_scraper.py

    请确保将/path/to/your/stock_scraper.py替换为实际的脚本路径。

通过以上步骤,你可以在Linux系统上实现每天自动抓取网站的最新收盘行情并保存到文件中。根据你所抓取网站的具体HTML结构,你可能需要调整解析数据的部分。

tigercitytaiwan commented 1 month ago

台股今日文化創意業類股表現疲軟,15日10:19相關指數下跌2.13%,總成交額11.02億元,大盤占比2.09%。 該產業上漲家數6、下跌家數14、平盤家數5。領跌個股鈊象(3293-TW)15日10:19股價下跌45元,報1460.0元,跌幅2.99%。 文化創意產業指數近5日上漲10.09%,櫃買市場加權指數下跌0.78%,產業指數漲幅表現優於大盤。

tigercitytaiwan commented 1 month ago

美國前總統川普周六(13 日)險遭暗殺,周日一大早在社群平台上發文,回應前一天槍擊案,提到了「團結」和「銘記」。 川普周日在社群平台 Truth Social 上表示,感謝每個人,感謝大家周六的關心和祈禱,因為只有上帝才能阻止這種難以想象的事情發生。「我們不會害怕,相反的,我們在面對邪惡時保持堅韌不拔。