|
东方财富网首页有个《公司聚焦》栏目,多数情况下是6条上市公司的负面消息。点击《公司聚焦》后进入上市公司频道,里头沪深上市公司的负面消息多一点。
关注这些信息,可主动回避一些问题股。但这些消息隔天就换一批,怎么把每天的这些上市公司信息下载下来,保存在自己的电脑上?
以下这个VBA小程序,可以解决这个问题。
因为PYTHON抓取数据比较方便,所以先用PYTHON抓取东方财富网两个页面的相关数据,再用VBA整理数据。
Sub 黑名单()
Call Shell("C:\Python\Python36\Python.exe D:\mypython\东方财富网-公司聚焦1.py", vbNormalFocus)
Application.Wait (Now + TimeValue("00:00:10"))
Call Shell("C:\Python\Python36\Python.exe D:\mypython\东方财富网-公司聚焦2.py", vbNormalFocus)
Application.Wait (Now + TimeValue("00:00:10"))
Set wkb1 = Workbooks.Open("D:\B001上市日期和所属概念.xlsx")
x1 = wkb1.Sheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Row
y1 = wkb1.Sheets("sheet1").Cells(1, Columns.Count).End(xlToLeft).Column
stockcodeandname = Range(Cells(1, 1), Cells(x1, 2))
Set wkb2 = Workbooks.Open("D:\mypython\公司聚焦.xlsx")
x2 = wkb2.Sheets("公司聚焦").Cells(Rows.Count, 1).End(xlUp).Row
y2 = wkb2.Sheets("公司聚焦").Cells(1, Columns.Count).End(xlToLeft).Column
m = Range("a2").Value
gsjj1 = Range(Cells(2, 1), Cells(x2, y2))
Set wkb3 = Workbooks.Open("D:\mypython\公司聚焦2.xlsx")
x3 = wkb3.Sheets("公司聚焦2").Cells(Rows.Count, 1).End(xlUp).Row
y3 = wkb3.Sheets("公司聚焦2").Cells(1, Columns.Count).End(xlToLeft).Column
gsjj2 = Range(Cells(2, 1), Cells(x3, y3))
ThisWorkbook.Activate
Sheets("黑名单").Activate
With Sheets("黑名单")
x4 = .Cells(Rows.Count, 1).End(xlUp).Row
y4 = .Cells(1, Columns.Count).End(xlToLeft).Column
For Each rg2 In .Range("c2:c" & x4)
View4 = CDate(m)
If rg2 = View4 Then
cnt = cnt + 1
End If
Next
If cnt >= 1 Then
MsgBox "已经保存过了"
Else
.Cells(x4 + 1, 3).Resize(UBound(gsjj1), UBound(gsjj1, 2)) = gsjj1
.Cells(x4 + x2, 3).Resize(UBound(gsjj2), UBound(gsjj2, 2)) = gsjj2
For Each rg In .Range(Cells(x4 + 1, 4), Cells(x4 + x2 + x3, 4))
For i = 2 To UBound(stockcodeandname)
view1 = rg.Value
view2 = stockcodeandname(i, 2)
If InStr(rg, stockcodeandname(i, 2)) Then
rg.Offset(0, -3) = stockcodeandname(i, 1)
rg.Offset(0, -2) = stockcodeandname(i, 2)
End If
Next
Next
End If
Set r1 = .Range(Cells(2, 1), Cells(x4 + x2 + x3, 5))
r1.Font.Name = "宋体"
r1.Font.Size = "9"
End With
wkb1.Close
wkb2.Close
wkb3.Close
End Sub
|
-
输出结果:
|