How to take automatic screenshot of a list of webpages and save [Fermé]

- - Dernière réponse : ucfoutu
Messages postés
18039
Date d'inscription
lundi 7 décembre 2009
Statut
Modérateur
Dernière intervention
11 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:

picture.Save("C:\" + WebBrowser1.DocumentTitle + ".Jpeg", System.Drawing.Imaging.ImageFormat.Jpeg)

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).
Afficher la suite 

2 réponses

Messages postés
13854
Date d'inscription
mardi 11 mars 2003
Statut
Contributeur
Dernière intervention
22 octobre 2019
312
0
Merci
Bonjour

CodeS SourceS est un forum francophone, ou la politesse est appréciée.
2 options s'offrent à vous:

Dans les 2 cas, merci de suivre la procédure décrite ici http://codes-sources.commentcamarche.net/faq/10686-le-nouveau-codes-sources-comment-ca-marche#balises-code%20la%20coloration%20syntaxique pour poster votre code.

Messages postés
18039
Date d'inscription
lundi 7 décembre 2009
Statut
Modérateur
Dernière intervention
11 avril 2018
212
0
Merci
Bonjour, Whismeril,
Et en plus en très mauvais anglais dont on voit bien que ce n'est pas la langue maternelle du demandeur. On observe également qu'il a "distribué" des copiés/collés d'une première demande faite sur un autre site.
https://social.msdn.microsoft.com/Forums/en-US/dae100c6-e0ac-4250-bc36-67b9bf876fc6/vbnet-how-to-take-automatic-screenshot-of-a-list-of-webpages-and-save-it-in-folder?forum=vbgeneral
Je ferme la présente discussion (pour lui permettre de voir ta réponse) puis la supprimerai dans 24 heures.


________________________
Nul ne saurait valablement coder ce qu'il ne saurait exposer clairement.