1

I have a wierd problem, I take a list of words, and create screenshots by doing google search on words.. after it creates like 50 screenshots it starts creating blank images!!

can someone help me solve the problem!

PS: Let me know if i need to be more clear!

this is the code i use to create the screenshot... on my main page i just loop on my words!

can someone help me solve the problem

public class GeneateScreenshot
 {
 public void GenerateScreenshot()
  {

  }
public Bitmap GenerateScreenshot(string url)
{
    // This method gets a screenshot of the webpage
    // rendered at its full size (height and width)

    return GenerateScreenshot(url, -1, -1);
}

public Bitmap GenerateScreenshot(string url, int width, int height)
{
    // Load the webpage into a WebBrowser control

    WebBrowser wb = new WebBrowser();
    wb.ScrollBarsEnabled = false;
    wb.ScriptErrorsSuppressed = true;
    wb.Navigate(url);
    while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }


    // Set the size of the WebBrowser control
    wb.Width = width;
    wb.Height = height;

    if (width == -1)
    {
        // Take Screenshot of the web pages full width
        wb.Width = wb.Document.Body.ScrollRectangle.Width;
    }

    if (height == -1)
    {
        // Take Screenshot of the web pages full height
        wb.Height = wb.Document.Body.ScrollRectangle.Height;
    }

    // Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
    Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
    wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
    wb.Dispose();

    return bitmap;
}

}

helpme
  • 570
  • 1
  • 7
  • 26
  • 1
    How fast is this looping through? Google doesn't like automated queries, and I wouldn't be surprised if you are getting a blank webpage itself. I would recommend possibly saving the resulting HTML of the web browser control every few loads and see if the HTML changes drastically at a point. – MindingData May 30 '12 at 22:48
  • like 100 queries in 7-8 mins!! – helpme May 31 '12 at 02:43

1 Answers1

1

I suspect that the DrawToBitmap function is not the right way to convert a WebBrowser control to an image. Check out the following links, looks like you need to use some native methods to do it reliably:

WebBrowser.DrawToBitmap() or other methods?

Converting WebBrowser.Document To A Bitmap?

http://www.codeproject.com/Articles/58605/HTML-to-Image-in-C

P.S. When playing with this code, I was picked up by Google's robot detector very quickly, so you may have trouble there as well.

Community
  • 1
  • 1
WildCrustacean
  • 5,896
  • 2
  • 31
  • 42