Data update
This commit is contained in:
parent
157b70a810
commit
8e4e15fa56
78 changed files with 2016 additions and 222 deletions
66
Task/Web-scraping/FreeBASIC/web-scraping.basic
Normal file
66
Task/Web-scraping/FreeBASIC/web-scraping.basic
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#include "windows.bi"
|
||||
#include "win/wininet.bi"
|
||||
|
||||
Const BUFFER_SIZE = 4096
|
||||
|
||||
Function GetWebPage(url As String) As String
|
||||
Dim As HINTERNET hInternet = InternetOpen("TimeGetter", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0)
|
||||
Dim As String resultado = ""
|
||||
|
||||
If hInternet Then
|
||||
Dim As HINTERNET hConnect = InternetOpenUrl(hInternet, url, NULL, 0, INTERNET_FLAG_RELOAD, 0)
|
||||
|
||||
If hConnect Then
|
||||
Dim As String buffer = Space(BUFFER_SIZE)
|
||||
Dim As DWORD bytesRead
|
||||
|
||||
Do
|
||||
If InternetReadFile(hConnect, Strptr(buffer), BUFFER_SIZE, @bytesRead) Then
|
||||
If bytesRead = 0 Then Exit Do
|
||||
resultado &= Left(buffer, bytesRead)
|
||||
End If
|
||||
Loop
|
||||
|
||||
InternetCloseHandle(hConnect)
|
||||
End If
|
||||
InternetCloseHandle(hInternet)
|
||||
End If
|
||||
|
||||
Return resultado
|
||||
End Function
|
||||
|
||||
Function ScrapeTime(pageAddress As String, timeZone As String) As String
|
||||
Dim As String page = GetWebPage(pageAddress)
|
||||
|
||||
If Len(page) = 0 Then Return "Cannot connect"
|
||||
|
||||
Dim As Integer startPos = 1
|
||||
Do
|
||||
Dim As Integer endPos = Instr(startPos, page, "<BR>")
|
||||
If endPos = 0 Then endPos = Len(page)
|
||||
|
||||
Dim As String linea = Mid(page, startPos, endPos - startPos)
|
||||
|
||||
If Instr(linea, timeZone) Then
|
||||
For i As Integer = 1 To Len(linea) - 7
|
||||
Dim As String char1 = Mid(linea, i, 1)
|
||||
Dim As String char2 = Mid(linea, i+4, 1)
|
||||
If char1 >= "0" And char1 <= "9" And Mid(linea, i+2, 1) = ":" And _
|
||||
char2 >= "0" And char2 <= "9" And Mid(linea, i+5, 1) = ":" Then
|
||||
Return Mid(linea, i, 8)
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
|
||||
If endPos = Len(page) Then Exit Do
|
||||
startPos = endPos + 4
|
||||
Loop
|
||||
|
||||
Return "Time not found"
|
||||
End Function
|
||||
|
||||
' Main program
|
||||
Dim As String url = "https://rosettacode.org/wiki/Talk:Web_scraping"
|
||||
Print ScrapeTime(url, "UTC")
|
||||
|
||||
Sleep
|
||||
Loading…
Add table
Add a link
Reference in a new issue