使用适用于Mac的VBA从网站获取文本



如果这是一个非常基本的问题,我很抱歉,但我真的很绝望。我想获取网站 https://cactus.nci.nih.gov/chemical/structure/78-70-6/smiles 的输出,并使用VBA将其输入Excel单元格。有谁知道一种简单直接的方法?

在某种程度上,我想要像"curl"这样的东西,在bash中,但它可以在Excel的VBA中使用。

我正在使用 Excel for Mac,版本 16.16.14,带有 VBA 7.1。

我已经尝试了许多在线建议的方法,但似乎没有任何方法适用于我的 Excel 版本。

多谢。

这应该可以解决问题;

Dim InternetExplorer As Object 'dim your internet explorer
Dim WebsiteURL As String: WebsiteURL = "https://cactus.nci.nih.gov/chemical/structure/78-70-6/smiles" 'dim and set your website url
Dim WebsiteText As String 'dim a variable to store the website text
Set InternetExplorer = CreateObject("InternetExplorer.Application") 'set your internet explorer
With InternetExplorer
.Visible = 1 'set to show (if you put 0 the browser would be hidden - just remember to set to nothing at end)
.navigate WebsiteURL 'navigates to websiteurl
While .Busy Or .readyState <> 4 'waits for page to load
DoEvents
Wend
End With
Dim WebPage As HTMLDocument 'dim your webpage as htmldocument
Set WebPage = InternetExplorer.document 'set your webpage to the internet explorer
WebsiteText = WebPage.body.innerText: Range("A1").Value = WebsiteText 'puts website text into variable : write to whatever cell you want

编辑: 刚刚注意到你对MAC说 - 我的坏,因为这使用IE浏览器

最新更新