Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Xhtml class in C#???

asp.net xhtml

  • Please log in to reply
19 replies to this topic

#13 Tonchi

Tonchi

    Helping the world with programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1249 posts
  • Location:Zagreb
  • Programming Language:C#, Others
  • Learning:C, C++, Python, JavaScript, Transact-SQL, Assembly

Posted 24 July 2011 - 08:23 AM

ok problems solved

now i have a next problem...you have give me a code:

...
 foreach (HtmlNode node in doc.DocumentNode.SelectNodes(
                "/div/div/table[@id='tabelaTec1']/tbody/tr")) {
                //add a new listview [B]item for each item in the table[/B]
                scrapeResults.Items.Add(new ListViewItem(new string[] {
                    
                     node.SelectSingleNode("td[@class='colFond']/a").InnerText, //scrape the appropriate fields
                     node.SelectSingleNode("td[@class='colDatum']").InnerText,
                     node.SelectSingleNode("td[@class='colVrijednost']").InnerText,
                     node.SelectSingleNode("td[@class='colValuta']").InnerText
                }));
            }
...
just look what did i bolded...i want to take only 2 items...how can i write to take only 2 items not all
  • 0

#14 sam_coder

sam_coder

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 380 posts

Posted 24 July 2011 - 08:40 AM

well, the easiest way to do this, without changing much would be to simply test each row.

if node.SelectSingleNode("td[@class='colFond']/a").InnerText == "a value your looking for"

the 'proper' way to do what you want is to update the xpath query, and add an appropriate predicate.

I highly recommend you read up on an xpath tutorial. it's easy to learn, and it's very powerful!
  • 0

#15 Tonchi

Tonchi

    Helping the world with programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1249 posts
  • Location:Zagreb
  • Programming Language:C#, Others
  • Learning:C, C++, Python, JavaScript, Transact-SQL, Assembly

Posted 24 July 2011 - 09:15 AM

ok i made it tnx...the only one thing i have to do is to add a new column...i add it but obvious i can't define which name is of column after
node.SelectSingleNode("td[@class='colVrijednost']").InnerText
on page it's Promj. % but it's not the name of that column
  • 0

#16 sam_coder

sam_coder

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 380 posts

Posted 24 July 2011 - 10:41 AM

well thats the trick. See, what I'm extracting here has very little to do with what you see in the page. What it is doing, is treating the HTML document itself like XML.

td[@class='something'] means your looking for this.

<td class="something">

the something isn't the name of the column, what I'm saying is match the element td, with an attribute called class, who's value is set to something.

You need to look at the HTML source of the page, to find that out
  • 0

#17 Tonchi

Tonchi

    Helping the world with programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1249 posts
  • Location:Zagreb
  • Programming Language:C#, Others
  • Learning:C, C++, Python, JavaScript, Transact-SQL, Assembly

Posted 24 July 2011 - 10:48 AM

ok i managed it
and for sure the last thing i need is to do this:

content = content.Substring(
                content.IndexOf("<div id=\"primary_content\""));
and
foreach (HtmlNode node in doc.DocumentNode.SelectNodes(
                "/div/div/table[@id='market_snap_us']/tbody/tr"))
but from pages Stock Market & Financial Markets Overview - Bloomberg , World Indexes: Asia/Pacific - Bloomberg and World Indexes: Europe, Africa & Middle East - Bloomberg

if you do that it would be all i need for my project
i'm asking you that because i don't know html so i can't find what i need inside html code
tnx
  • 0

#18 Tonchi

Tonchi

    Helping the world with programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1249 posts
  • Location:Zagreb
  • Programming Language:C#, Others
  • Learning:C, C++, Python, JavaScript, Transact-SQL, Assembly

Posted 31 July 2011 - 09:28 AM

please can you do that so i can understand what to do in the future
  • 0

#19 sam_coder

sam_coder

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 380 posts

Posted 31 July 2011 - 09:32 AM

Tonchi,

I've already shown you how to do it. with a fully working solution.


but from pages Stock Market & Financial Markets Overview - Bloomberg , World Indexes: Asia/Pacific - Bloomberg and World Indexes: Europe, Africa & Middle East - Bloomberg

if you do that it would be all i need for my project
i'm asking you that because i don't know html so i can't find what i need inside html code


please can you do that so i can understand what to do in the future


I'm not going to do your whole project for you. =)
  • 0

#20 Tonchi

Tonchi

    Helping the world with programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1249 posts
  • Location:Zagreb
  • Programming Language:C#, Others
  • Learning:C, C++, Python, JavaScript, Transact-SQL, Assembly

Posted 01 August 2011 - 03:27 PM

it's not whole...it's just that i can't define path like that "/div/div/table[@id='market_snap_us']/tbody/tr"
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download