Board logo

標題: [發問] 抓證交所個股日成交資訊時,被擋IP怎麼解決 [打印本頁]

作者: tsunamix03    時間: 2018-1-30 21:54     標題: 抓證交所個股日成交資訊時,被擋IP怎麼解決

各位先進大大好
    最近在抓證交所的個股日成交資訊時,
    抓到大約第24、25筆資料時,疑似IP就被擋
    程式會跳出記憶體不足便結束
    接下來連用一般瀏覽器也不能瀏覽證交所網頁
    所以才會猜測IP被擋
    不知道該如何解決?
    先謝謝各位先進大大
   
    程式碼如下


    '需更改從哪一支股票開始抓
    stockID = Array(1101, 1102, 1103, 1104, 1108, 1109, 1110, 1201, 1203, 1210, 1213, 1215, 1216, 1217, 1218, 1219, 1220, 1225, 1227, 1229, 1231, 1232, 1233, 1234, 1235, 1236, 1256, 1262, 1301, 1303, 1304, 1305, 1307, 1308,   
    1309, 1310, 1312, 1313, 1314, 1315, 1316, 1319, 1321, 1323, 1324, 1325, 1326, 1337, 1338, 1339, 1340, 1402, 1409, 1410, 1413, 1414, 1416, 1417, 1418, 1419, 1423, 1432, 1434, 1435, 1436, 1437, 1438, 1439, 1440, 1441, 1442,
    1443, 1444, 1445, 1446, 1447, 1449, 1451, 1452, 1453, 1454, 1455, 1456, 1457, 1459, 1460, 1463, 1464, 1465, 1466, 1467, 1468, 1469, 1470, 1471, 1472, 1473, 1474, 1475, 1476, 1477, 1503, 1504, 1506, 1507, 1512, 1513, 1514,
    1515, 1516, 1517, 1519, 1521, 1522, 1524, 1525, 1526, 1527, 1528, 1529, 1530, 1531, 1532, 1533, 1535, 1536, 1537, 1538, _
    1539, 1540, 1541, 1558, 1560, 1568, 1582, 1583, 1589, 1590, 1592, 1598, 1603, 1604, 1605, 1608, 1609, 1611, 1612, 1614, 1615, 1616, 1617, 1618, 1626, 1701, 1702, 1704, 1707, 1708, 1709, 1710, 1711, 1712, 1713, 1714, 1717,
    1718, 1720, 1721, 1722, 1723, 1724, 1725, 1726, 1727, 1730, 1731, 1732, 1733, 1734, 1735, 1736, 1737, 1762, 1773, 1776, 1783, 1786, 1789, 1802, 1805, 1806, 1808, 1809, 1810, 1817, 1902, 1903, 1904, 1905, 1906, 1907, 1909,
    2002, 2006, 2007, 2008, 2009, 2010, 2012, 2013, 2014, 2015, 2017, 2020, 2022, 2023, 2024, 2025, 2027, 2028, 2029, 2030, 2031, 2032, 2033, 2034, 2038, 2049, 2059, 2062, 2069, 2101, 2102, 2103, 2104, 2105, 2106, 2107, 2108,
    2109, 2114, 2115, 2201, 2204, 2206, 2207, 2208, 2227, 2228, 2231, 2236, _
    2236, 2239, 2243, 2301, 2302, 2303, 2305, 2308, 2311, 2312, 2313, 2314, 2316, 2317, 2321, 2323, 2324, 2325, 2327, 2328, 2329, 2330, 2331, 2332, 2337, 2338, 2340, 2342, 2344, 2345, 2347, 2348, 2349, 2351, 2352, 2353, 2354,
    2355, 2356, 2357, 2358, 2359, 2360, 2362, 2363, 2364, 2365, 2367, 2368, 2369, 2371, 2373, 2374, 2375, 2376, 2377, 2379, 2380, 2382, 2383, 2385, 2387, 2388, 2390, 2392, 2393, 2395, 2397, 2399, 2401, 2402, 2404, 2405, 2406,
    2408, 2409, 2412, 2413, 2414, 2415, 2417, 2419, 2420, 2421, 2423, 2424, 2425, 2426, 2427, 2428, 2429, 2430, 2431, 2433, 2434, 2436, 2438, 2439, 2440, 2441, 2442, 2443, 2444, 2448, 2449, 2450, 2451, 2453, 2454, 2455, 2456,
    2457, 2458, 2459, 2460, 2461, 2462, 2464, 2465, 2466, 2467, 2468, 2471, 2472, 2474, 2475, 2476, 2477, 2478, 2480, 2481, _
    2482, 2483, 2484, 2485, 2486, 2488, 2489, 2491, 2492, 2493, 2495, 2496, 2497, 2498, 2499, 2501, 2504, 2505, 2506, 2509, 2511, 2514, 2515, 2516, 2520, 2524, 2527, 2528, 2530, 2534, 2535, 2536, 2537, 2538, 2539, 2540, 2542,
    2543, 2545, 2546, 2547, 2548, 2597, 2601, 2603, 2605, 2606, 2607, 2608, 2609, 2610, 2611, 2612, 2613, 2614, 2615, 2616, 2617, 2618, 2633, 2634, 2636, 2637, 2642, 2701, 2702, 2704, 2705, 2706, 2707, 2712, 2722, 2723, 2727,
    2731, 2739, 2748, 2801, 2809, 2812, 2816, 2820, 2823, 2832, 2834, 2836, 2838, 2841, 2845, 2849, 2850, 2851, 2852, 2855, 2856, 2867, 2880, 2881, 2882, 2883, 2884, 2885, 2886, 2887, 2888, 2889, 2890, 2891, 2892, 2897, 2901,
    2903, 2904, 2905, 2906, 2908, 2910, 2911, 2912, 2913, 2915, 2923, 2929, 2936, 2939, 3002, 3003, 3004, 3005, 3006, 3008, 3010, 3011 )


    Dim row As Integer, col As Integer, stock_array, date_array
    row = 0
    col = 0
    yr = 2017
    mnth = "06"
   
   
    For i = 0 To 100

            '以下取得股價資料

            Url = "http://www.tse.com.tw/exchangeReport/STOCK_DAY?response=text&date=" & yr & mnth & "01&stockNo=" & stockID(i)
            Set XML = CreateObject("Microsoft.XMLHTTP")
            Set Stream = CreateObject("ADODB.stream")
        
            XML.Open "GET", Url, 0
            XML.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
            XML.send thePOSTdata
   
            With Stream
               
                .Type = 1
                .Mode = 3
                .Open
                .Write XML.responseBody
                .Position = 0
                .Type = 2
                .Charset = "Big5"
                ByteToText = .ReadText
                MsgBox ByteToText

                'arr = Split(ByteToText, "[[")       'Chr(10)代表Enter鍵嗎???
               
            End With
            
    Next
作者: flask    時間: 2018-2-12 13:19

間隔5秒再抓下一筆不要連續抓
作者: joey0415    時間: 2018-2-14 19:51

回復 1# tsunamix03



這是只其中一種等待的方法

for i=XXX to XXX
Application.Wait Now + TimeValue("00:00:03")

next

作者: Scott090    時間: 2018-2-15 08:07

回復 1# tsunamix03


   上市上櫃個股有 1700多檔,每隔幾秒抓一次恐怕要2個多小時。
建議到鉅亨網去抓歷史資料會好很多, 它不會擋IP




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)