V
V
VirusesAnalystCoder2020-06-19 14:08:34
C++ / C#
VirusesAnalystCoder, 2020-06-19 14:08:34

How to get the value from the javascript code of the site?

Hello!
Generally. I don't understand how can I get the value from the div in which the span?
For example, I make a get request to the site and get the source code.
I have this code:

<!DOCTYPE html><html lang="en-US"><head><title>**</title>
...
urnover":87018612238,"turnover24h":13135834196879,"homeNotional24h":131358.3419687911,"foreignNotional24h":1227821955,"prevPrice24h":9456,"vwap":9347.5416,"highPrice":9456.5,"lowPrice":9226,"lastPrice":9393.5,"lastPriceProtected":9394,"lastTickDirection":"MinusTick","lastChangePcnt":-0.0066,"bidPrice":9393.5,"midPrice":9393.75,"askPrice":9394,"impactBidPrice":9393.1993,"impactMidPrice":9393.75,"impactAskPrice":9394.0817,"hasLiquidity":true,"openInterest":618600881,"openValue":6585624979126,"fairMethod":"FundingRate","fairBasisRate":0.1095,"fairBasis":0.11,"fairPrice":9393.17,"markMethod":"FairPrice","markPrice":9393.17,"indicativeTaxRate":0,"indicativeSettlePrice":9393.06,"optionUnderlyingPrice":null,"settledPrice":null,"timestamp":"2020-06-19T11:04:18.600Z"},{"symbol":"XBTM20","rootSymbol":"XBT
...

Here.
Among all this, there is bidPrice and lastPrice, written like this:
"lastPrice":111.0
I need to somehow pull out the number after lastPrice
The number there can be different.
I tried using json but it's not json!
It's more of a javascript site code.
There is also a delay on the site. When you enter - there is a download for 5 seconds, and then only the site is shown.
If you do not go through the download - just the same is displayed.
BUT still there is the number I need, which I need to get.
Tell me how to do it?
This is the source code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Net;

namespace Parser
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Начинаю работу.");
            string page = "";

            WebRequest request = WebRequest.Create("**");
            request.Credentials = CredentialCache.DefaultCredentials;
            
            WebResponse response = request.GetResponse();
            Console.WriteLine(((HttpWebResponse)response).StatusDescription);
            using (Stream dataStream = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(dataStream);
                string responseFromServer = reader.ReadToEnd();
                reader.Close();
                page = responseFromServer;
            }
            
            response.Close();
        }
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mletov, 2020-06-19
@mletov

Read about regular expressions, you need a regular expression like this

["]lastPrice["]:([0-9]+)(([.]([0-9]+))?)
, only with quotes escaped

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question