Solved

Help using winsock to get html source code

Posted on 2004-04-12
15
1,034 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

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

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…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

688 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