How to get data from iframes

c# html-agility-pack iframe web-scraping

Question

 <td>
   <iframe>
     #document
       <html>
         <body>
           <table>
             <tbody>
               <tr>..<tr>
                <tr>
                   <td>
<select id="selYear" onchange="document.getElementById('selCat').selectedIndex=0;  
document.g…tedIndex=0;document.getElementById('frmFindParts').submit();"
 name="year">
 <option value=""></option>
 <option value="2014"></option>
                   </td>
                </tr>
             </tbody>
       </table><body></html></iframe></tr>

I need the data within the value of option, with an output of 2014. I employ C#. I specifically need the xpath for this. This is my code.

var html = PageRetriever.ReadFromServer(pqi.URL, false);
            var htmlDoc = new HtmlDocument();
            htmlDoc.LoadHtml(html);
            var tags = htmlDoc.DocumentNode.SelectNodes("Xpath please");
1
0
6/27/2014 12:20:27 PM

Popular Answer

You may test it like this:

var result = htmlDoc.DocumentNode
                .SelectNodes("//iframe//table//select[@id='selYear']/option[@value!='']")
                .Select(o => o.Attributes["value"].Value);
//this will print : 2014
foreach (string s in result)
{
    Console.WriteLine(s);
}
1
6/27/2014 12:48:39 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