Forum » Programiranje » [C#] Prosim pomagajte! Potrebujem program, ki bi pobiral podatke iz ene strani
[C#] Prosim pomagajte! Potrebujem program, ki bi pobiral podatke iz ene strani
David1994 ::
Rad bi napravil program, ki bi mi iz spletne strani pobral 3 stringe (oznacene na sliki).
Pred kratkim sem tle ze tezil za source pobirat, vendar mi ni prav uspelo
Hvala v naprej!
LP, David
Pred kratkim sem tle ze tezil za source pobirat, vendar mi ni prav uspelo
Hvala v naprej!
LP, David
jure1825 ::
ja odpreš stran pol pa greš čez vse div-e in poiščeš tistega ki ima id=1, 2 in 3.
sej vidiš da je v sourceu:
div id="1" ...
sej vidiš da je v sourceu:
div id="1" ...
Kostko ::
V Pythonu lahko narediš skoraj v eni vrstici:
To vrne seznam vseh treh vrednosti, trenutno ['5,14', '13.07.2007', '1,05']. V drugih jezikih podobno, ključen je tist regularni izraz tam...
import urllib2, re re.compile('<div id="[123]" .*?nowrap>(.*?)</div>').findall(urllib2.urlopen('http://www.abancna-dzu.si/vipek.asp').read())
To vrne seznam vseh treh vrednosti, trenutno ['5,14', '13.07.2007', '1,05']. V drugih jezikih podobno, ključen je tist regularni izraz tam...
Human stupidity is not convergent, it has no limit!
StratOS ::
Če že hočeš kr kreacijo out.txt z podatki je rešitev tukaj
Drugače pa sploh ni problem iskati takšne podatke.
Drugače pa sploh ni problem iskati takšne podatke.
<div id="1" style="position: absolute; visibility: visible; left: 602px; top: 209px; color: #009900; width:50px; text-align:right;" nowrap>5,14</div> <div id="2" style="position: absolute; visibility: visible; left: 670px; top: 209px; color: #009900; width:50px; text-align:right;" nowrap>13.07.2007</div> <div id="3" style="position: absolute; visibility: visible; left: 736px; top: 209px; color: #009900; width:36px; text-align:right;" nowrap>1,05</div>
"Multitasking - ability to f##k up several things at once."
"It works better if you plug it in."
"The one who is digging the hole for the other to fall in is allready in it."
"It works better if you plug it in."
"The one who is digging the hole for the other to fall in is allready in it."
David1994 ::
StratOS, tvoja resitev je super, a bi mi lahko poslal source, saj bi rad naredil, da bi mi avtomatsko preračunalo, koliko je vrednost vsega skupaj, kar imam. Namrec, ne bi rad uporabljal streamreaderja.
LP, David
LP, David
StratOS ::
Hja, ni v C-ju ampak v VB-ju, napisana na hitro ...
Uporablja par API-jev.
No source lahko vseeno prilepim :
Uporablja par API-jev.
No source lahko vseeno prilepim :
Attribute VB_Name = "GetUrl" Option Explicit Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long Public Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal sURL As String, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long Public Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer Public Const IF_FROM_CACHE = &H1000000 Public Const IF_MAKE_PERSISTENT = &H2000000 Public Const IF_NO_CACHE_WRITE = &H4000000 Private Const BUFFER_LEN = 256 Public Function GetUrlSource(sURL As String) As String Dim sBuffer As String * BUFFER_LEN, iResult As Integer, sData As String Dim hInternet As Long, hSession As Long, lReturn As Long 'get the handle of the current internet connection hSession = InternetOpen("vb wininet", 1, vbNullString, vbNullString, 0) 'get the handle of the url If hSession Then hInternet = InternetOpenUrl(hSession, sURL, vbNullString, 0, IF_NO_CACHE_WRITE, 0) 'if we have the handle, then start reading the web page If hInternet Then 'get the first chunk & buffer it. iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn) sData = sBuffer 'if there's more data then keep reading it into the buffer Do While lReturn <> 0 iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn) sData = sData + Mid(sBuffer, 1, lReturn) Loop End If 'close the URL iResult = InternetCloseHandle(hInternet) GetUrlSource = sData End Function Sub Main() Dim i As Long Dim i1 As Long Dim Tmp As String Dim S(2) As String Const f1 As String = "<div id=" & """" & "1" & """" & " style=" & """" & "position: absolute; visibility: visible; left: 602px; top: 209px; color: #009900; width:50px; text-align:right;" & """" & " nowrap>" Const f2 As String = "<div id=" & """" & "2" & """" & " style=" & """" & "position: absolute; visibility: visible; left: 670px; top: 209px; color: #009900; width:50px; text-align:right;" & """" & " nowrap>" Const f3 As String = "<div id=" & """" & "3" & """" & " style=" & """" & "position: absolute; visibility: visible; left: 736px; top: 209px; color: #009900; width:36px; text-align:right;" & """" & " nowrap>" Const f4 As String = "</div>" Tmp = GetUrlSource("http://www.abancna-dzu.si/vipek.asp") i = InStr(1, Tmp, f1) i1 = InStr(i + 1, Tmp, f4) S(0) = Mid$(Tmp, i + Len(f1), i1 - i - Len(f1)) i = InStr(i1 + 1, Tmp, f2) i1 = InStr(i + 1, Tmp, f4) S(1) = Mid$(Tmp, i + Len(f2), i1 - i - Len(f2)) i = InStr(i1 + 1, Tmp, f3) i1 = InStr(i + 1, Tmp, f4) S(2) = Mid$(Tmp, i + Len(f3), i1 - i - Len(f3)) Open "out.txt" For Output As #1 For i = 0 To 2 Print #1, S(i) Next i Close #1 End Sub
"Multitasking - ability to f##k up several things at once."
"It works better if you plug it in."
"The one who is digging the hole for the other to fall in is allready in it."
"It works better if you plug it in."
"The one who is digging the hole for the other to fall in is allready in it."
Kostko ::
Whoa, tale VB je pa skor tolk eleganten kot Python
Human stupidity is not convergent, it has no limit!
mHook ::
Ni problem v jeziku.
Tut v VBju se da narest enostavno:
Tut v VBju se da narest enostavno:
Public Function GetVipek() As MatchCollection Dim url As String = "http://www.abancna-dzu.si/vipek.asp" Dim regex As String = "<div id=""[123]"" .*?nowrap>(.*?)</div>" Dim response As String = New WebClient().DownloadString(url) Return New Regex(regex).Matches(response) End Function
StratOS ::
Hja, v VB6 :)
in ne v .net :)
in ne v .net :)
"Multitasking - ability to f##k up several things at once."
"It works better if you plug it in."
"The one who is digging the hole for the other to fall in is allready in it."
"It works better if you plug it in."
"The one who is digging the hole for the other to fall in is allready in it."
darkolord ::
Čist isti šmorn, namesto webclienta uporabiš inet, regex pa uporabiš iz scripting runtime-a
David1994 ::
Najlepsa hvala vsem, se posebej mHooku in StratOSu. Na internetu sem konvertiral kodo ki mi jo je mHook napisal in izgleda nekako takole:
public MatchCollection GetVipek()
{
string url = "http://www.abancna-dzu.si/vipek.asp";
string regex = /* tega kosa nemorem pokazat ker mi skripta foruma na pusti */;
string response = new WebClient().DownloadString(url);
return new Regex(regex).Matches(response);
}
Lp, David
public MatchCollection GetVipek()
{
string url = "http://www.abancna-dzu.si/vipek.asp";
string regex = /* tega kosa nemorem pokazat ker mi skripta foruma na pusti */;
string response = new WebClient().DownloadString(url);
return new Regex(regex).Matches(response);
}
Lp, David
David1994 ::
Ok mam se en mali problemcek.
V double bi rad pritisnu eno decimalno stevilo. Pa mi zmeri nardi error "Input string was not in a correct format."
A mislite da je to bug v novem Visual C# "Orcas", ker je beta, zato vprasam... Koda pa izgleda nakako takole.
Meni ne izgleda nic narobe... vam?
V double bi rad pritisnu eno decimalno stevilo. Pa mi zmeri nardi error "Input string was not in a correct format."
A mislite da je to bug v novem Visual C# "Orcas", ker je beta, zato vprasam... Koda pa izgleda nakako takole.
double stevilka; string tekst = 0,07; stevilka = double.Parse(tekst);
Meni ne izgleda nic narobe... vam?
David1994 ::
sam unos je ze pravi... ker ubistvu tale string skine od drugod... tko da tiste navednice res nimajo fore...
in ce bi bil problem bi mi zatezilo v vrstici kjer sem definiral tekst, ne v vrstici kjer se tekst konvertira...
in ce bi bil problem bi mi zatezilo v vrstici kjer sem definiral tekst, ne v vrstici kjer se tekst konvertira...
mHook ::
double.Parse ti parsa tako kot je nastavljeno v System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.
V primeru culture sl-SI je privzeta vrednost za decimalke "," (vejica). "." (pika) v tem primeru kot ločilo za decimalke ne deluje - ga ignorira.
Če želiš drugače uporabi Double.Parse Method (String, IFormatProvider) ali pa v CurrentCulture.NumberFormat (ali kar celo CurrentCulture) od CurrentThread nastavi tisto, kar rabiš.
V primeru culture sl-SI je privzeta vrednost za decimalke "," (vejica). "." (pika) v tem primeru kot ločilo za decimalke ne deluje - ga ignorira.
Če želiš drugače uporabi Double.Parse Method (String, IFormatProvider) ali pa v CurrentCulture.NumberFormat (ali kar celo CurrentCulture) od CurrentThread nastavi tisto, kar rabiš.
David1994 ::
Ok da nebom glih nove teme odpiral bom kar tle... iz borze na strani dela bi rad pobral vrednost krke... kako naj v vkodi definiram naj mi dobi dve vrstici nizje od tega?
<tr bgcolor="#F0F0F0" title="KRKA"> //// tle je vrstica ki me ne zanima // ta je pa taprava
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | [VB] Komunikacija s serijskimi napravamiOddelek: Programiranje | 2314 (1588) | mNeRo |
» | Excel vprašanjeOddelek: Programiranje | 1152 (1051) | matic |
» | Vb6Oddelek: Programiranje | 1338 (1201) | StratOS |
» | API+VBOddelek: Programiranje | 2106 (1810) | webblod |
» | Odpiranje dat.exe v VBOddelek: Programiranje | 3004 (2797) | webblod |