How do I parse a WebPage using HTML tags in VBScript
I try to extract the price of Bitcoin from https://coinmarketcap.com/ using VBScript.
I have the following HTML code:
<td class="no-wrap text-right" data-sort="4329.6071152">
<a class="price" href="/currencies/bitcoin/#markets" data-btc="1.0" data-usd="4329.6071152">$4,329.61</a>
</td>
So I wrote this script for the vbs file:
set objIE =nothing
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = false
objIE.Navigate "https://coinmarketcap.com/"
Do
WScript.Sleep 100
Loop Until objIE.ReadyState = 4
msgbox objIE.document.getElementsByTagName("/currencies/bitcoin/#markets")
objIE.Quit()
My expected result is "4329.6071152" but the actual result is:
parsing vbscript
add a comment |
I try to extract the price of Bitcoin from https://coinmarketcap.com/ using VBScript.
I have the following HTML code:
<td class="no-wrap text-right" data-sort="4329.6071152">
<a class="price" href="/currencies/bitcoin/#markets" data-btc="1.0" data-usd="4329.6071152">$4,329.61</a>
</td>
So I wrote this script for the vbs file:
set objIE =nothing
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = false
objIE.Navigate "https://coinmarketcap.com/"
Do
WScript.Sleep 100
Loop Until objIE.ReadyState = 4
msgbox objIE.document.getElementsByTagName("/currencies/bitcoin/#markets")
objIE.Quit()
My expected result is "4329.6071152" but the actual result is:
parsing vbscript
add a comment |
I try to extract the price of Bitcoin from https://coinmarketcap.com/ using VBScript.
I have the following HTML code:
<td class="no-wrap text-right" data-sort="4329.6071152">
<a class="price" href="/currencies/bitcoin/#markets" data-btc="1.0" data-usd="4329.6071152">$4,329.61</a>
</td>
So I wrote this script for the vbs file:
set objIE =nothing
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = false
objIE.Navigate "https://coinmarketcap.com/"
Do
WScript.Sleep 100
Loop Until objIE.ReadyState = 4
msgbox objIE.document.getElementsByTagName("/currencies/bitcoin/#markets")
objIE.Quit()
My expected result is "4329.6071152" but the actual result is:
parsing vbscript
I try to extract the price of Bitcoin from https://coinmarketcap.com/ using VBScript.
I have the following HTML code:
<td class="no-wrap text-right" data-sort="4329.6071152">
<a class="price" href="/currencies/bitcoin/#markets" data-btc="1.0" data-usd="4329.6071152">$4,329.61</a>
</td>
So I wrote this script for the vbs file:
set objIE =nothing
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = false
objIE.Navigate "https://coinmarketcap.com/"
Do
WScript.Sleep 100
Loop Until objIE.ReadyState = 4
msgbox objIE.document.getElementsByTagName("/currencies/bitcoin/#markets")
objIE.Quit()
My expected result is "4329.6071152" but the actual result is:
<td class="no-wrap text-right" data-sort="4329.6071152">
<a class="price" href="/currencies/bitcoin/#markets" data-btc="1.0" data-usd="4329.6071152">$4,329.61</a>
</td>
<td class="no-wrap text-right" data-sort="4329.6071152">
<a class="price" href="/currencies/bitcoin/#markets" data-btc="1.0" data-usd="4329.6071152">$4,329.61</a>
</td>
parsing vbscript
parsing vbscript
edited Nov 23 '18 at 12:12
BOB
asked Nov 23 '18 at 11:55
BOBBOB
4481618
4481618
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You're getting a collection of HTML nodes with your query. You should try a more specific one and also getting its attributes:
MsgBox objIE.document.QuerySelectorAll("a[href='/currencies/bitcoin/#markets']").Item(0).getAttribute("data-usd")
Thanks iBug, I didn't know that in VBScript you can use CSSSelector. This is very usefull !
– BOB
Nov 23 '18 at 12:54
If I want to extract "$4,329.61" how can I do? Because it's a little bit different
– BOB
Nov 23 '18 at 13:00
1
@BOB You can use.innerText
for that.
– iBug
Nov 23 '18 at 13:29
add a comment |
Since the row of the table has the id attribute set. You can get the text content of the cell this way:
objIE.document.GetElementById("id-bitcoin").Cells(3).InnerText
It's working but where did you get "id-bitcoin" ?
– BOB
Nov 23 '18 at 13:09
I saw it<tr id="id-bitcoin" class="odd" role="row">
– BOB
Nov 23 '18 at 13:10
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446261%2fhow-do-i-parse-a-webpage-using-html-tags-in-vbscript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You're getting a collection of HTML nodes with your query. You should try a more specific one and also getting its attributes:
MsgBox objIE.document.QuerySelectorAll("a[href='/currencies/bitcoin/#markets']").Item(0).getAttribute("data-usd")
Thanks iBug, I didn't know that in VBScript you can use CSSSelector. This is very usefull !
– BOB
Nov 23 '18 at 12:54
If I want to extract "$4,329.61" how can I do? Because it's a little bit different
– BOB
Nov 23 '18 at 13:00
1
@BOB You can use.innerText
for that.
– iBug
Nov 23 '18 at 13:29
add a comment |
You're getting a collection of HTML nodes with your query. You should try a more specific one and also getting its attributes:
MsgBox objIE.document.QuerySelectorAll("a[href='/currencies/bitcoin/#markets']").Item(0).getAttribute("data-usd")
Thanks iBug, I didn't know that in VBScript you can use CSSSelector. This is very usefull !
– BOB
Nov 23 '18 at 12:54
If I want to extract "$4,329.61" how can I do? Because it's a little bit different
– BOB
Nov 23 '18 at 13:00
1
@BOB You can use.innerText
for that.
– iBug
Nov 23 '18 at 13:29
add a comment |
You're getting a collection of HTML nodes with your query. You should try a more specific one and also getting its attributes:
MsgBox objIE.document.QuerySelectorAll("a[href='/currencies/bitcoin/#markets']").Item(0).getAttribute("data-usd")
You're getting a collection of HTML nodes with your query. You should try a more specific one and also getting its attributes:
MsgBox objIE.document.QuerySelectorAll("a[href='/currencies/bitcoin/#markets']").Item(0).getAttribute("data-usd")
answered Nov 23 '18 at 12:33
iBugiBug
19k53362
19k53362
Thanks iBug, I didn't know that in VBScript you can use CSSSelector. This is very usefull !
– BOB
Nov 23 '18 at 12:54
If I want to extract "$4,329.61" how can I do? Because it's a little bit different
– BOB
Nov 23 '18 at 13:00
1
@BOB You can use.innerText
for that.
– iBug
Nov 23 '18 at 13:29
add a comment |
Thanks iBug, I didn't know that in VBScript you can use CSSSelector. This is very usefull !
– BOB
Nov 23 '18 at 12:54
If I want to extract "$4,329.61" how can I do? Because it's a little bit different
– BOB
Nov 23 '18 at 13:00
1
@BOB You can use.innerText
for that.
– iBug
Nov 23 '18 at 13:29
Thanks iBug, I didn't know that in VBScript you can use CSSSelector. This is very usefull !
– BOB
Nov 23 '18 at 12:54
Thanks iBug, I didn't know that in VBScript you can use CSSSelector. This is very usefull !
– BOB
Nov 23 '18 at 12:54
If I want to extract "$4,329.61" how can I do? Because it's a little bit different
– BOB
Nov 23 '18 at 13:00
If I want to extract "$4,329.61" how can I do? Because it's a little bit different
– BOB
Nov 23 '18 at 13:00
1
1
@BOB You can use
.innerText
for that.– iBug
Nov 23 '18 at 13:29
@BOB You can use
.innerText
for that.– iBug
Nov 23 '18 at 13:29
add a comment |
Since the row of the table has the id attribute set. You can get the text content of the cell this way:
objIE.document.GetElementById("id-bitcoin").Cells(3).InnerText
It's working but where did you get "id-bitcoin" ?
– BOB
Nov 23 '18 at 13:09
I saw it<tr id="id-bitcoin" class="odd" role="row">
– BOB
Nov 23 '18 at 13:10
add a comment |
Since the row of the table has the id attribute set. You can get the text content of the cell this way:
objIE.document.GetElementById("id-bitcoin").Cells(3).InnerText
It's working but where did you get "id-bitcoin" ?
– BOB
Nov 23 '18 at 13:09
I saw it<tr id="id-bitcoin" class="odd" role="row">
– BOB
Nov 23 '18 at 13:10
add a comment |
Since the row of the table has the id attribute set. You can get the text content of the cell this way:
objIE.document.GetElementById("id-bitcoin").Cells(3).InnerText
Since the row of the table has the id attribute set. You can get the text content of the cell this way:
objIE.document.GetElementById("id-bitcoin").Cells(3).InnerText
answered Nov 23 '18 at 13:03
Regis DesrosiersRegis Desrosiers
35719
35719
It's working but where did you get "id-bitcoin" ?
– BOB
Nov 23 '18 at 13:09
I saw it<tr id="id-bitcoin" class="odd" role="row">
– BOB
Nov 23 '18 at 13:10
add a comment |
It's working but where did you get "id-bitcoin" ?
– BOB
Nov 23 '18 at 13:09
I saw it<tr id="id-bitcoin" class="odd" role="row">
– BOB
Nov 23 '18 at 13:10
It's working but where did you get "id-bitcoin" ?
– BOB
Nov 23 '18 at 13:09
It's working but where did you get "id-bitcoin" ?
– BOB
Nov 23 '18 at 13:09
I saw it
<tr id="id-bitcoin" class="odd" role="row">
– BOB
Nov 23 '18 at 13:10
I saw it
<tr id="id-bitcoin" class="odd" role="row">
– BOB
Nov 23 '18 at 13:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53446261%2fhow-do-i-parse-a-webpage-using-html-tags-in-vbscript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown