How to take automatic screenshot of a list of webpages and save
Fermé
martin
-
5 mars 2016 à 21:03
ucfoutu
Messages postés18038Date d'inscriptionlundi 7 décembre 2009StatutModérateurDernière intervention11 avril 2018
-
6 mars 2016 à 04:48
I've these controls on actual form:
[CODE]Textbox/CODE (Where at each cycle, there will be a new link with the webbrowser show it);
[CODE]Webbrowser/CODE (To check if the page (for example the first on the textbox) is full loaded, and after take an automatic screenshot of the full page).
Now this program should read each link pasted on the textbox, and a cycle, that will increment, only if, when the page is full loaded, and after screenshots are saved in a default folder, after this can go ahead with the second,ecc. This is the code, i was starting:
[CODE]Imports System.IO
Imports System.Drawing
Imports System.Threading
Imports System.Windows.Forms
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim tempArray As String()
tempArray = TextBox1.Lines
For counter = 0 To tempArray.Length - 1
WebBrowser1.Navigate(tempArray(counter))
Next
End Sub
End Class/CODE
My problem now is how can i say to the program to wait for page full loading and then take a screenshot and save it to a default folder. (A full page screenshot ) ?
I tried this for wait until page loading is completed:
While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
End While
Next
but now i have a strange fact, with one link inserted in textbox, it load ok, and when i exit to the program no errors appears. But with 2 link on textbox, the cycle work, fast but it's working, except when i exit to the program it give me an error.
I tried this part of code for get the screenshots of the web page\s , but the result it's a blank image of that dimension.
[CODE]Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim tempArray As String()
Dim picture As New Bitmap(1440, 4000)
tempArray = TextBox1.Lines
For counter = 0 To tempArray.Length - 1
WebBrowser1.Width = 1440
WebBrowser1.Height = 4000
WebBrowser1.Navigate(tempArray(counter))
WebBrowser1.DrawToBitmap(picture, New Rectangle(WebBrowser1.Location.X, WebBrowser1.Location.Y, WebBrowser1.Width, WebBrowser1.Height))
picture.Save("C:\test.jpeg")
While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
End While
Next
End Sub/CODE
After a while i was thinking i made it with this (but the form sometime need to be full screen or not working, but this isn't important because it's working too with normal form size, except sometimes it give a blank image, i think is webbrowser.drawtobitmap() with the refresh):
[CODE]Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim tempArray As String()
Dim picture As New Bitmap(1440, 4000)
tempArray = TextBox1.Lines
For counter = 0 To tempArray.Length - 1
WebBrowser1.Width = 1440
WebBrowser1.Height = 4000
WebBrowser1.Navigate(tempArray(counter))
WebBrowser1.DrawToBitmap(picture, New Rectangle(WebBrowser1.Location.X, WebBrowser1.Location.Y, WebBrowser1.Width, WebBrowser1.Height))
Me.WebBrowser1.Refresh()
picture.Save("C:\test1.Jpeg", System.Drawing.Imaging.ImageFormat.Jpeg)
While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete
Application.DoEvents()
End While
Next
End Sub/CODE
And this is the result (not maded with cycled but one by one for test, another strange this is the webbrowser can't read well how much links textbox have):
http://i.stack.imgur.com/Z9qrl.jpg (with the google page)
http://i.stack.imgur.com/fmaqv.jpg (with the youtube page)
http://i.stack.imgur.com/iIqqY.jpg(with the tvdb page)
And with this, i want to know if it's possible to fix the issues of blank images and long name error with the save function and webbrowser1.documentTitle into picture.save, like you can see below.
For the name picture file with every cycle(sometimes working and other not) with this:
but have a issues too there, because with long name it give me the System.NotSupportedException, and when get webpage like google it get two files, one without name and blank and another with name and content (but usually blank).
ucfoutu
Messages postés18038Date d'inscriptionlundi 7 décembre 2009StatutModérateurDernière intervention11 avril 2018211 Modifié par ucfoutu le 6/03/2016 à 04:51