How to extract values in quote marks from HTML string?

c# html html-agility-pack javascript web-scraping

Question

The following line of code was taken from a website and is what I have:

<li class="player" data-id="168568" data-teamid="156" data-x="142.33" data-y="297.16040000000004" data-name="Corentin Tolisso" data-position="3">Corentin Tolisso<span class="shirt">24</span></li>

The name "Corentin Tolisso," the shirt size "24," and the data-x and data-y variables are the things I'm trying to extract.

I have so far been successful in making it function with values that are within>...< HTML Agility Pack is used.

The numbers from data-x and data-y cannot be extracted, however, for some reason.

I cloned the HTML string into a new jsfiddle so that it would display precisely what my C# code is receiving, including the elements in between.>...< .

How can I get data-x and data-values? y's

The following:String.IndexOf works perfectly, but flexibility is lost. This is the backup plan I use.

Note 2: Although here and here gave me some insight, I still struggled to adapt it to C#.

1
0
7/2/2018 2:38:08 PM

Popular Answer

one method would be to use(["'])(?:(?=(\\?))\2.)*?\1 It also supports nested quotations.

Click on this link to test it out: https://regex101.com/r/cB0kB8/1

It's pretty easy to do using JQuery.

Check out this sample as well: Obtaining HTML text input value

<form name="input" action="handle_email.php" method="post">
Email: <input type="text" name="email" />
<input type="submit" value="Newsletter" />
</form> 
<a id="regLink" href="http://mywebsite.com/register?user_email=">Register</a>

$('input[name="email"]').change(function(){
alert($('#regLink').attr('href')+$('input[name="email"]').val());
});

Hope it's useful to you!

1
7/2/2018 2:52:38 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow