Hallo Torsten, danke für den Tipp, ich habe jetzt an anderer Stelle erfahren, dass der Internet Explorer (wer hätte es gedacht) nicht der beste Weg ist für web scraping. Sollte das Thema zufällig noch jemanden interessieren, ich versuche jetzt mein Glück mit dem folgenden Code:
Sub Aktienscreener1()
Dim Cell As Range
Dim LoHi As Variant
Dim HTMLdoc As Object
Dim n As Long
Dim op As String
Dim oTable As Object
Dim oTables As Object
Dim PageSrc As String
Dim pc As String
Dim pe As Variant
Dim RngBeg As Range
Dim RngEnd As Range
Dim URL As String
Dim yr As String
Dim Wks As Worksheet
Set Wks = ActiveSheet
Set RngBeg = Wks.Range("A2")
Set RngEnd = Wks.Cells(Rows.Count, RngBeg.Column).End(xlUp)
If RngEnd.Row < RngBeg.Row Then Exit Sub
Set HTMLdoc = CreateObject("htmlfile")
With CreateObject("MSXML2.ServerXMLHTTP")
For Each Cell In Wks.Range(RngBeg, RngEnd)
DoEvents ' Pressing Ctrl+Break will interrupt the macro.
URL = "https://finance.yahoo.com/quote/" & Cell & "?p=" & Cell & ""
.Open "GET", URL, False
.Send
If .Status <> 200 Then
MsgBox "Error: " & .Status & " - " & .statusText
Exit Sub
End If
PageSrc = .responseText
HTMLdoc.Write PageSrc
HTMLdoc.Close
Set oTables = HTMLdoc.GetElementsByTagName("table")
Set oTable = oTables(0)
pc = oTable.Rows(0).Cells(1).innerText ' Previous Close
op = oTable.Rows(1).Cells(1).innerText ' Opening Price
yr = oTable.Rows(5).Cells(1).innerText ' 52 week Range
LoHi = Split(yr, " - ") ' Element (0) is the 52 week low and element (1) is the 52 week High.
Set oTable = oTables(1)
pe = oTable.Rows(2).Cells(1).innerText ' PE Ratio
Cell.Offset(0, 1).Resize(1, 4).Value = Array(pc, op, LoHi(1), pe)
Next Cell
End With
End Sub
|