如何从html标记<a>

时间:2017-11-22 12:00:19

标签: html asp.net httpwebrequest

i use HttpWebRequest Method in asp web Page to read a page and import that page to my own page.in that page i have to retrive a specific Value (price) that reside in a tag. used code is this:

var req = HttpWebRequest.Create("http://www.somewhere.com/webservice/price_live.php?new=1&bg=f0f4f6&upc=196900&dc=FF0000&obc=f9f9f9&oc=09334d&ebc=ffffff&ec=09334d&hbc=09334d&hc=ffffff&fs=13");
            req.Method = WebRequestMethods.Http.Get;
            var res = req.GetResponse();

            Stream dataStream = res.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            string ResponseFromServer = reader.ReadToEnd();
            res.Close();
            this.TextBox1.Text = (ResponseFromServer);

this code serves me whole html page, inside of that page exist tag like this:

<td class="text-left" ><a id="Goal" style="color:#FF0000" href="http://www.somewhere.com" target="_blank">127,000</a></td>

now how can i have "127000" and save that?!

2 个答案:

答案 0 :(得分:0)

使用它,将Anchor的值存储到一个新变量中:

var linkval = document.getElementById('goal').innerHTML;

它会将Value存储到变量&#34; linkval&#34;。

答案 1 :(得分:0)

<a id="Goal" style="color:#FF0000" href="http://www.somewhere.com" target="_blank"> 
is first child of  <td class="text-left" > 

因此,您可以在javascipt中进行,如下所示

$('td:first-child a').text();

and then convert it to a number for further usage