Reputation: 345
I have been trying to use Selenium WebDriver (Chrome) to load a page and get disqus comment threads. Please see the code.
public static void Main(string[] args)
{
var driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://nation.com.pk/blogs/05-Apr-2016/should-qandeel-baloch-s-strip-tease-really-be-a-rallying-cause-for-liberalism");
var userNameField = driver.FindElementById("disqus_thread").GetAttribute("outerHTML");
Console.WriteLine(userNameField);
Console.Read();
}
It gives the following output.
<div id="disqus_thread"><iframe id="dsq-app2" name="dsq-app2" allowtransparency="true" frameborder="0" scrolling="no" tabindex="0" title="Disqus" width="100%" src="http://disqus.com/embed/comments/?base=default&version=af1a2e2611136ef6c314afec2806cef3&f=nawaiwaqt&t_u=http%3A%2F%2Fnation.com.pk%2Fblogs%2F05-Apr-2016%2Fshould-qandeel-baloch-s-strip-tease-really-be-a-rallying-cause-for-liberalism&t_d=Should%20Qandeel%20Baloch%E2%80%99s%20%E2%80%98striptease%E2%80%99%20really%20be%20a%20rallying%20cause%20for%20liberalism%3F&t_t=Should%20Qandeel%20Baloch%E2%80%99s%20%E2%80%98striptease%E2%80%99%20really%20be%20a%20rallying%20cause%20for%20liberalism%3F&s_o=default" style="width: 1px !important; min-width: 100% !important; border: none !important; overflow: hidden !important; height: 652px !important;" horizontalscrolling="no" verticalscrolling="no"></iframe></div>
Which is contrary to my expectations as I was hoping to get comments html at this stage. How can I modify this code to get the comment thread? PS: there is no indication of iframe in original page source.
Upvotes: 0
Views: 239
Reputation: 345
So here is how I could get the iframe source code for further processing. Hope it helps someone else.
var driver = new ChromeDriver();
int tmp = 1;
foreach(string file in File.ReadLines(@"bla bla bla\Bloglinks.txt"))
{
driver.Navigate().GoToUrl(file);
driver.SwitchTo().Frame("dsq-app2");
var userNameField = driver.PageSource;
File.WriteAllText(@"bla bla bla\Comments\"+tmp+".html", userNameField);
Console.WriteLine(file);
tmp++;
}
driver.Close();
Upvotes: 1