標題:
[發問]
如何找到正確的網址,讓EXCEL匯入WEB查詢
[打印本頁]
作者:
bioleon69
時間:
2016-9-24 18:35
標題:
如何找到正確的網址,讓EXCEL匯入WEB查詢
本帖最後由 bioleon69 於 2016-9-24 18:38 編輯
http://www.cmoney.tw/finance/f00026.aspx?s=2330
想要把此網址匯入,用EXCEL的web查詢
(基本資料那份表格)
結果,失敗
用fiddler找到get網址
http://www.cmoney.tw/finance/ashx/mainpage.ashx?action=GetStockListLatestSaleData&stockId=2330&cmkey=XYlSc5pnmuVR2Cz27paqpg%3D%3D&_=1474712478440
一樣,失敗
如何找到正確網址,再把2330改成變數
用iqy方式匯入excel
以下為匯入成功案例的iqy檔案 (YAHOO股市)
[attach]25331[/attach]
作者:
joey0415
時間:
2016-9-24 21:35
回復
1#
bioleon69
在tivo168也看到你的回文
這不用能匯入的
要先去它的
網頁,取得 cmkey=XYlSc5pnmuVR2Cz27
每檔股票不一樣後,再轉到你要去的頁面才行
至少我前以是這麼做的
此網站主要避免你直接爬取它的資料
您再觀察看看
作者:
bioleon69
時間:
2016-9-25 01:01
有點聽不太懂XDD
作者:
bioleon69
時間:
2016-9-27 09:00
有大俠知道如何抓取嗎!!!!
感謝
作者:
GBKEE
時間:
2016-10-1 06:58
回復
4#
bioleon69
Option Explicit
Sub Ex_網頁元素()
Dim i As Integer, xlTab As Object, R As Integer, C As Integer
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate "http://www.cmoney.tw/finance/f00026.aspx?s=2330"
' .Navigate "http://www.cmoney.tw/finance/f00026.aspx?s=" & 變數
Do While .Busy Or .readyState <> 4: DoEvents: Loop
Set xlTab = .Document.ALL.tags("TABLE")(0)
With ActiveSheet
.UsedRange.Clear
For R = 0 To xlTab.Rows.Length - 1
For C = 0 To xlTab.Rows(R).Cells.Length - 1
.Cells(R + 1, C + 1) = xlTab.Rows(R).Cells(C).innertext
Next
Next
End With
.Quit '關閉網頁
End With
End Sub
複製代碼
作者:
bioleon69
時間:
2016-10-1 20:50
Option Explicit
Sub Ex_網頁元素()
Dim i As Integer, xlTab As Object, R As Integer, C As Integer, Surl$
Surl = "http://www.cmoney.tw/finance/f00026.aspx?s=& [A1].Value &"
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate " "
' .Navigate "http://www.cmoney.tw/finance/f00026.aspx?s=" & 變數
Do While .Busy Or .readyState <> 4: DoEvents: Loop
Set xlTab = .Document.ALL.tags("TABLE")(0)
With ActiveSheet
.UsedRange.Clear
For R = 0 To xlTab.Rows.Length - 1
For C = 0 To xlTab.Rows(R).Cells.Length - 1
.Cells(R + 1, C + 1) = xlTab.Rows(R).Cells(C).innertext
Next
Next
End With
.Quit '關閉網頁
End With
End Sub
複製代碼
請問一下~~
.Navigate " "這邊要怎麼插入定義的變數surl
作者:
c_c_lai
時間:
2016-10-2 05:58
回復
6#
bioleon69
原 6# 樓
Surl = "http://www.cmoney.tw/finance/f00026.aspx?s=& [A1].Value &"
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate " "
複製代碼
修正為:
Surl = "http://www.cmoney.tw/finance/f00026.aspx?s=" & Sheets("XXX").[A1]
With CreateObject("InternetExplorer.Application")
.Visible = True
.Navigate Surl
複製代碼
即可。
作者:
bioleon69
時間:
2016-10-2 14:16
回復
7#
c_c_lai
nice!!感謝
在請問一下
要讓這些資料從A3開始輸出 要怎麼修改?
作者:
c_c_lai
時間:
2016-10-2 17:19
回復
8#
bioleon69
For C = 0 To xlTab.Rows(R).Cells.Length - 1
.Cells(R + 1, C + 1) = xlTab.Rows(R).Cells(C).innertext
Next
複製代碼
調整為
For C = 0 To xlTab.Rows(R).Cells.Length - 1
.Cells(R + 3, C + 1) = xlTab.Rows(R).Cells(C).innertext
Next
複製代碼
作者:
bioleon69
時間:
2016-10-5 01:29
本帖最後由 bioleon69 於 2016-10-5 01:31 編輯
感謝GBK以及lai兩位大大
都成功了~~在請教一下
我想加入在A1如果沒有輸入正確變數
或者輸入錯誤
B1會呈現 請輸入正確股票代號
下面是有那裡有問題??
我加入了這幾串程式碼
On Error Resume Next
.Refresh False
[B1] = ""
If Err <> 0 Then
[B1] = "請輸入正確股票代號"
Else
End If
Option Explicit
Sub Ex_網頁元素()
Dim i As Integer, xlTab As Object, R As Integer, C As Integer, Surl$
Surl = "http://www.cmoney.tw/finance/f00026.aspx?s=" & Sheets("工作表1").[A1]
With CreateObject("InternetExplorer.Application")
.Visible = False
.Navigate Surl
Do While .Busy Or .readyState <> 4: DoEvents: Loop
Set xlTab = .Document.ALL.tags("TABLE")(0)
With ActiveSheet
.UsedRange.Clear
For R = 0 To xlTab.Rows.Length - 1
For C = 0 To xlTab.Rows(R).Cells.Length - 1
.Cells(R + 1, C + 1) = xlTab.Rows(R).Cells(C).innertext
On Error Resume Next
.Refresh False
[B1] = ""
If Err <> 0 Then
[B1] = "請輸入正確股票代號"
Else
End If
Next
Next
End With
.Quit '關閉網頁
End With
End Sub
複製代碼
作者:
GBKEE
時間:
2016-10-5 06:04
回復
10#
bioleon69
Option Explicit
Sub Ex_網頁元素()
Dim i As Integer, xlTab As Object, R As Integer, C As Integer, Surl$
If Sheets("工作表1").[A1] = "" Then MsgBox "請輸入正確股票代號": Exit Sub
Surl = "http://www.cmoney.tw/finance/f00026.aspx?s=" & Sheets("工作表1").[A1]
With CreateObject("InternetExplorer.Application")
.Visible = False
.Navigate Surl
Do While .Busy Or .readyState <> 4: DoEvents: Loop
Set xlTab = .Document.ALL.tags("TABLE")(0)
If Not xlTab Is Nothing Then
With ActiveSheet
.UsedRange.Clear
For R = 0 To xlTab.Rows.Length - 1
For C = 0 To xlTab.Rows(R).Cells.Length - 1
.Cells(R + 1, C + 1) = xlTab.Rows(R).Cells(C).innertext
Next
Next
End With
Else
MsgBox "請輸入正確股票代號"
End If
.Quit '關閉網頁
End With
End Sub
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)