Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a working statement in PHP using the simple dom parser that I want to convert into C# using the HTML Agility Pack.

I am really struggling and have not been able to get anything even close to working. Here is my PHP DOM Parser code that I want to convert to C#:

PHP
<?php 
include 'simple_html_dom.php';
if(isset($_GET['date']))
{
    $url = 'http://10.8.32.20/Default.aspx?Menu=' . $_GET['date'];
}

$html = file_get_html('http://localhost:81/curl/thu.php');

// echo ($html);

//foreach($html->find('td[align="right]') as $e)
    // echo $e->innertext . '<br>';
//echo $html->find('td[align="right"]', 1)->plaintext.'<br><hr>';

echo '<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>';
foreach($html->find('div#grid') as $e)
    echo $e->innertext . '<br>';

?>
Posted

1 solution

try htmlagilitypack[^]. you can install it as nuget package[^].
sample code:
C#
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(url);
var liOfTravels = doc.DocumentNode.SelectSingleNode("//div[@id='myTrips']")
                 .SelectNodes(".//li");
 
Share this answer
 
Comments
Member 11530690 12-Jun-15 5:25am    
thanks you can give me one full sample code ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900