Here this may help its in C# but you might learn something.
How To Get Content From A Website
I am plan to write a program in visual basic to fetch a information from website and to display in My program. In that website i can information after log in so in my program i must log in into that and fetch a Information from my program so i need help from you guys .
please help me
Here this may help its in C# but you might learn something.
How To Get Content From A Website
This is how I do it. This code is in Delphi, but its easy to convert to VB. Add a webbrowser control to your form. (You might have to register the control)
Navigate to the site you want to automate. The webbrowser control has a "DocumentComplete" event. (This is common to all languages since its taken from the ActiveX control)
Get the DOM interface. Again, this is the same for all languages. Then the rest is simple DOM coding. You can find tons of DOM coding in all languages. ie: JavaScript, C#, VB, Delphi, C++Builder etc. Its all the same.
Its just a matter of attempting to enter data into forms and submiting the data. If it fails (ie: Thows an exception), then you try your next automation code. Sometimes you need to look though all the links to find the one you want, and then click() it. Selecting the link can be done via either the innerHTML or href attributes (there are other ways, like if you know the link is the 4th link on the page, etc)
anyway, here is the code. This log's into MySpace and navigates to the "edit bio" page and changes the user bio. A simple form.submit() would automate the update of your myspace bio, which might be a cool tool.
Code:procedure TFormMain.FormCreate(Sender: TObject); begin WebBrowser.Navigate('http://www.myspace.com'); end; procedure TFormMain.WebBrowserDocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant); var document, links, form: OleVariant; I: Integer; begin document := WebBrowser.Document; links := document.links; try form := document.all.LoginForm; form.ctl00_ctl00_cpMain_cpMain_LoginBox_Email_Textbox.value := '**EMAIL**'; form.ctl00_ctl00_cpMain_cpMain_LoginBox_Password_Textbox.value := '**PASSWORD**'; form.submit(); Exit; except end; try form := document.all.myForm; form.interest.value := 'Yo'; Exit; except end; for I := 0 to links.length - 1 do begin if AnsiContainsText(links.item(I).innerText, 'Safe Mode') then begin links.item(I).click(); Exit; end; end; for I := 0 to links.length - 1 do begin if AnsiContainsText(links.item(I).href, 'editInterest') and AnsiContainsText(links.item(I).href, 'bio') then begin links.item(I).click(); Exit; end; end; end;
The down side to this method is the images that are also downloaded. You can access the registry to switch off the image downloading IE, or just do it by hand if this is your own personal app.
In delphi I use TEmbeddedWB which is an extend TWebBrowser that supports lots of custom localized IE browser settings like disabling images, javascript, popups, etc.
PS: TEmbeddedWB is avaliable from here. If anyone is looking for a one-stop-shop for all your IE hacking needs, look here. Its in Delphi, but it is mostly Win32/COM/ActiveX coding.
Downloads EmbeddedWB
Last edited by alienkinetics; 02-09-2010 at 02:27 AM. Reason: spelling
btw, if you ever want to know what is in the DOM interface, read some of this:
IHTMLDocument2 Interface ()
That is where I go when I need to know what is avaliable. You can do some really cool things.
Code:Imports System.IO Imports System.Net Imports System.Text Class WebRetrieve Public Shared Sub Main() Dim wr As HttpWebRequest = CType(WebRequestFactory.Create("http://maps.weather.com/web/radar/us_orl_ultraradar_large_usen.jpg"), HttpWebRequest) Dim ws As HttpWebResponse = CType(wr.GetResponse(), HttpWebResponse) Dim str As Stream = ws.GetResponseStream() Dim inBuf(100000) As Byte Dim bytesToRead As Integer = CInt(inBuf.Length) Dim bytesRead As Integer = 0 While bytesToRead > 0 Dim n As Integer = str.Read(inBuf, bytesRead, bytesToRead) If n = 0 Then Exit While End If bytesRead += n bytesToRead -= n End While Dim fstr As New FileStream("weather.jpg", FileMode.OpenOrCreate, FileAccess.Write) fstr.Write(inBuf, 0, bytesRead) str.Close() fstr.Close() End Sub 'Main End Class 'WebRetrieve
Share your Knowledge, It's one way to achieve immortality.
My Website | My Community | My Magazine | My YouTube
There are currently 1 users browsing this thread. (0 members and 1 guests)