Solved

Help using winsock to get html source code

Posted on 2004-04-12
15
1,027 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

713 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