iT邦幫忙

0

【已解決】上櫃資料爬蟲

reed 2024-07-10 16:06:011511 瀏覽
  • 分享至 

  • xImage

想請問大神
我參考網路資料想爬蟲上櫃當天資料,範例程式櫃買連結如下

def crawl_price(date):
    datestr = (datetime.date.today() - datetime.timedelta(max(1,(datetime.date.today().weekday() + 6) % 7 - 3))).strftime("%Y/%m/%d")
    datestr = str(int(datestr2[:4])-1911)+datestr2[4:]    #113/7/10
    r =requests.get('http://www.tpex.org.tw/web/stock/aftertrading/daily_close_quotes/stk_quote_download.php?l=zh-tw&d='+ datestr +'&s=0,asc,0')

但爬下來的都是昨日盤後資料?
https://ithelp.ithome.com.tw/upload/images/20240710/20148072XRYZ06TN6A.png
複製程式裡連結,並把變數 datestr 打上今日日期,畫面顯示的是今天收盤資訊
https://ithelp.ithome.com.tw/upload/images/20240710/20148072CFxQpaLJbw.png
不曉得是哪一個環節出問題,才能成功爬下當天資訊,而非昨天資訊

再請網路大神們解惑

更新:後來發現自己寫錯
datestr = datetime.date.today().strftime("%Y/%m/%d")這樣就可以了

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
qweuio1122
iT邦見習生 ‧ 2024-07-11 12:32:00

大神 請問 如何聯絡你 是TG 還是LINE 能留個聯絡方式嗎 非常想跟您學習!

我要發表回答

立即登入回答