Solved

Help using winsock to get html source code

Posted on 2004-04-12
15
1,017 Views
Last Modified: 2013-11-13
I need to be able to get the HTML source code from a website and parse the code for the file names I need to download. Any help?

This is the code I have tried to use, but the Winsock1_Connect() procedure is never envoked.

********************************
(Global variables)
Private m_sPage as string
Private Const m_sDownloadSite as string = "https://telemarketing.donotcall.gov/Download/DnldFull.aspx"
********************************
**************************
Main code
**************************
    sHost = Mid(m_sDownloadSite, InStr(m_sDownloadSite, "://") + 3)
    If InStr(sHost, "/") > 0 Then
         m_sPage = Mid(sHost, InStr(sHost, "/"))
        sHost = Left(sHost, InStr(sHost, "/") - 1)
    Else
        m_sPage = "/"
    End If

    If InStr(sHost, ":") > 0 Then
        lPort = Mid(sHost, InStr(sHost, ":") + 1)
        sHost = Left(sHost, InStr(sHost, ":") - 1)
    Else
        lPort = 80
    End If

    With Winsock1
        If .State <> sckClosed Then .Close
        .RemoteHost = sHost
        .RemotePort = lPort
        .Connect
    End With

Code used from this website:
http://www.ostrosoft.com/vb/projects/get_html_source.asp
0
Comment
Question by:brownkj1
  • 5
  • 4
  • 3
  • +2
15 Comments
 
LVL 6

Expert Comment

by:mirzas
ID: 10808004
for https the port is not 80
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10808268
do this:


Private Const m_sDownloadSite as string = "https://telemarketing.donotcall.gov:443/Download/DnldFull.aspx"
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10808270
Also since you are using HTTPs you are going to need to use teh INET control...because you are going to get encrypted data.



-Brian
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:brownkj1
ID: 10808400
Is the port I'm supposed to use 443 then?

Also, I changed the string to the above and still get nothing.

Any more help?
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10808484
You may be better off using a WebBrowser control since it seems you need to automate logging-in as well.
0
 

Author Comment

by:brownkj1
ID: 10808522
I already have automated that process and I do use the web browser. I was using this to download the files,

Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long


sDownloadFile = URLDownloadToFile(0, "http://download.donotcall.gov/Full/270_12_4_2004_z9b6y1g4ORDQAvErZdkdEA==.zip", "P:\Files\270.Zip, 0, 0)


but the file changes names every day so I need to capture these file names somehow. It was suggested to capture the HTML source code and parse it, but I don't know how to do that. Can you help?

0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10808523
Yes the port you are supposed to use is 443.
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 10808534
you need to use the INET Control that is the only way you are going to be able in the end ot get Clear Text HTML.


-Brian
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10808575
If you automate IE to log-in, you can automate it to get the file-names to download. If you automate Winsock to log-in, you'll still get encrypted data (as mentioned).
0
 

Author Comment

by:brownkj1
ID: 10808645
I guess I don't know how to automate the download of the file names. Could you elaborate?

Is it similar to doing something like this or???

IE.Document.All("txtActNumber").Value = m_sOrgId





0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 10809085
Does it automatically download after you log-in?

You can..

1.) Fill in the OrgID and Password (like you've shown above) and submit/click "Log-In".
2.) If it automatically downloads, skip to 3.), if not, you can automate clicking on a link to download.
3.) Watch for BeforeNavigate (for it to start downloading)... example:

Private Sub Form_Load()
    'This is just for testing.. so a DL can start
    WebBrowser1.Navigate "http://download.donotcall.gov/Full/270_12_4_2004_z9b6y1g4ORDQAvErZdkdEA==.zip"
End Sub
Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant, Headers As Variant, Cancel As Boolean)
    'If it's navigating to a zip file...
    If Right(LCase(URL), 4) = ".zip" Then
        'Cancel it so IE won't download it
        Cancel = True
        'Use URLDownloadToFile() to download file here instead of MsgBox
        MsgBox URL
    End If
End Sub

If you want a proper working example, you can email a user/pass for me to test to log-in. If not, you'll have to get it working from what I've described.
0
 

Author Comment

by:brownkj1
ID: 10813193
Unfortunately I can't give you a login to test with because it's dealing with customer information and I only have one secure id that's been given to me (and it's not my id, it's the user's I'm writing the application for).

The files do not automatically download once I get to the site.

And I was incorrect in saying I use the webbrowser component. I am declaring an object ("IE") and setting up that object to be an Internet Explorer Application.

Here are the processes I take:
1) Login
2) Navigate to download website
3) Download files by using URLDownloadToFile()

The problem that I'm having is I don't know how to get the file name. You have to assume here:

WebBrowser1.Navigate "http://download.donotcall.gov/Full/270_12_4_2004_z9b6y1g4ORDQAvErZdkdEA==.zip

that I don't know the name of that file (which is "270_12_4_2004_z9b6y1g4ORDQAvErZdkdEA==.zip"

I have been testing the downloads and application by getting file name from the website manually and then hard-coding it into the application. I can not do that any more, as I'm trying to push this app out to the user and it needs to be automated.

I have tried to automate the clicking of the link to download the file but it downloads an empty zip file.

Someone suggested getting the HTML source code and parsing it for the file name. Is there a way I can do that through the IE object?
0
 

Author Comment

by:brownkj1
ID: 10816803
I figured out a way to get the files downloaded, which is what I initially set out to do by grabbing the HTML source code. I figured a way to do it without getting the source code.

Thank you for the help.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 10848653
Closed, 500 points refunded.
modulo
Community Support Moderator
Experts Exchange
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to implement Singleton Design Pattern in Java.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question