Coder Social home page Coder Social logo

stockjob's Introduction

StockJob

自製的歷史股價爬蟲

目前使用 .NET Core 3.1.19 請自行安裝SDK

Getting Started

nlog.config記得填入你的Gmail並開啟第三方應用程式存取權(帳戶>安全性),才能收到Error信件

填入您的DB ConnectionString (請勿在Production或公開環境使用這方式設定)

class StockDBContext : DbContext
{
    public DbSet<StockHistory> StockHistory { get; set; }
        protected override void OnConfiguring(DbContextOptionsBuilder options)
        => options.UseSqlServer(""); //←填入您的DB ConnectionString
}

在StockJob/StockJob.csproj那層的目錄下使用Powershell輸入以下更新資料庫

dotnet tool install --global dotnet-ef
dotnet ef database update

用git sub module載入我的另一個Repository: StockLib


StockJob/Program.cs

爬201701到現在這個月為止的所有股價資料到資料庫

await runner.OneTimeCrawler(new DateTime(2017, 1, 1));

爬201701到現在這個月為止的台泥(1101)股價資料到資料庫

await runner.OneTimeCrawler("1101", new DateTime(2017, 1, 1));

爬201701到201801為止的所有股價資料到資料庫

await runner.OneTimeCrawler(new DateTime(2017, 1, 1), new DateTime(2018, 1, 1));

爬20170101到201901為止的台泥(1101)股價資料到資料庫

await runner.OneTimeCrawler("1101", new DateTime(2017, 1, 1), new DateTime(2019, 1, 1));

所有DateTime都是以月為單位,不是以天為單位,new DateTime(2017, 5, 15)代表2017年5月(忽視15)。

skipByMonth參數用途: 如果您重複跑本程式,已爬過的股票月份會跳過。這對於沒辦法一次跑完的時候很有幫助,如果你是在平日跑的話,記得最後再爬一次全部股票從當月到當月。

目前跑一筆一個月的股價會Delay 4~12秒(隨機),這是我找到不會被鎖IP的範圍,你可以找到更短的範圍當然更好,會越快跑完。

執行程式會有console給你看log,目前跑到哪裡 start program

邊跑你可以邊看DB內抓到的資料 alt text

stockjob's People

Contributors

trend-jacky-su avatar twjackysu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.