[英]How to gather the value of a specific <span> from a variable containing the complete web page code
I scraped a web page with the price of bitcoin and have the complete web page code stored in a variable. 我用比特币的价格抓取了一个网页,并将完整的网页代码存储在一个变量中。 How do I extract the span:
如何提取跨度:
<span class="text-large2" data-currency-value>8128.61</span>
from the whole code? 从整个代码? By the way the number 8128.61 changes every time the page is refreshed as the price is updated
顺便说一下,随着价格的更新,每次刷新页面时数字8128.61都会改变
Here is my full code: 这是我的完整代码:
$.getJSON('http://www.whateverorigin.org/get?url=' + encodeURIComponent('https://coinmarketcap.com/currencies/bitcoin/') + '&callback=?', function(data){ console.log(data.contents); });
body { background-color: lightblue; }
<!DOCTYPE html> <html> <body> <html lang="en"> <head> <title>Web Scraper</title> <link rel="stylesheet" href="css/style.css"> </head> <body> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="js/scripts.js"></script> </body> </html> </body>
you can use something like below to extract the value 您可以使用类似下面的方法来提取值
$.getJSON('http://www.whateverorigin.org/get?url=' + encodeURIComponent('https://coinmarketcap.com/currencies/bitcoin/') + '&callback=?', function(data){
console.log($(data.contents).find('span[data-currency-value]').html());
});
you can do this without Jquery also 你也可以不用Jquery
var htmlData = `your html`;
var divNode = document.createElement("div");
divNode.innerHTML = html;
after this you can access all HTML element which is inside htmlData
之后,您可以访问
htmlData
所有HTML元素
like 喜欢
divNode.getElementsByClassName("test")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.