Excel 求助大神,如何用VBA获取HTML中<head>里面的内容

Excel 求助大神,如何用VBA获取HTML中<head>里面的内容,第1张

<head>之间的内容可以用vba的正则表达式提取。

Function findFiveLetter(sentence)

Dim regEx As New VBScript_RegExp_55.RegExp

Dim matches, s

regEx.Pattern = "<head>.*?</head>"

regEx.IgnoreCase = True 'True to ignore case

regEx.Global = True 'True matches all occurances, False matches the first occurance

s = ""

If regEx.Test(sentence) Then

Set matches = regEx.Execute(sentence)

For Each Match In matches

s = s &" Position: " &Match.FirstIndex

s = s &" Word: " &Match.Value &" "

s = s &Chr(10)

Next

findFiveLetter = s

Else

findFiveLetter = ""

End If

End Function

可以做到的。也可以先整理出全部上市公司代码,网址的变化其实只有代码变化,把代码做成一个变量循环进去。

下载全部公司的10年内报表,大概要2个小时。

拔特,没有几把卵用。

比如你说的公司所属行业,除了大公司比如万科,就是做房地产的,其他的公司基本都会有主营业务发生变化,甚至没有主营业务。前几年有个概念热,上市公司都会往概念上靠,垃圾公司甚至变更自己的所属行业。

所以,没有用的,孩纸。关键还得自己分析他的报表。

用数据字典,dictionary value,item 。 value不允许重复。

Sub test()

Dim name()

Set dic = CreateObject("Scripting.Dictionary")

a = [a65536].End(xlUp).Row

For Each Cell In Worksheets("Sheet1").Range("A1:A" &a)

If Not dic.exists(Cell.Value) Then

dic.Add Cell.Value, Cell.Value

On Error Resume Next

End If

Next

name = dic.items

For i = 1 To dic.Count

Worksheets("Sheet1").Cells(i, 2) = name(i - 1)

Next

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zaji/7135610.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-02
下一篇 2023-04-02

发表评论

登录后才能评论

评论列表(0条)

保存