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 inside option value and output is 2014.I am using c#. I need the xpath for this exactly. here is my code

var html = PageRetriever.ReadFromServer(pqi.URL, false);
            var htmlDoc = new HtmlDocument();
            htmlDoc.LoadHtml(html);
            var tags = htmlDoc.DocumentNode.SelectNodes("Xpath please");

Popular Answer

You can try this way :

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);
}



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why