by effel » 26 Jun 2023, 08:49
Hallo Just Me,
vielen Dank. Ich habe
URLDownloadToVar(url) getestet, musste aber feststellen das es in meinem Fall nicht funktioniert, schon bei der ersten Abfrage bekomme ich eine Fehlermeldung.
Es läuft aber auch ohne ganz toll
- 06_26_23 @3_40_40.PNG (11.02 KiB) Viewed 876 times
Code: Select all
global startTime := a_tickCount
FileEncoding, UTF-8
; correction := "in münster und köln sind die strasen saubber"
correction := "wievieele Tankstelen gibtt es in münster und köln"
; correction := "dies ist ein fehlerfreier text, er wird im original zurück gegeben"
split := strSplit(function(correction),"`n","`r")
MsgBox % (split.1) ? (split.1 "`n`n" split.2 " mSec") : ""
exitapp
;#############
function(correction) {
url := "https://www.google.com/search?q=" (EncodeDecodeURI(correction,true, false)) "&ie=UTF-8"
toVar := true ; true erzeugt fehler 403
if toVar
{
html := URLDownloadToVar(url)
}else{
urlDownloadToFile,% url, tmp_html.html
FileRead, html, tmp_html.html
FileDelete, tmp_html.html
}
res=
loop, parse,% html, `n, `r
if inStr(a_loopField,">Ergebnisse f")
res := xStr(a_loopField,,"href=""/search?ie=UTF-8&q=","&spell=1")
res := strReplace(res,"+",a_space)
return (Result := EncodeDecodeURI(res,false, false))
? Result "`n" (a_tickCount-StartTime) ; return korriguert
: (error#403 := FEHLER(html))
? error#403 "`n" (a_tickCount-StartTime) ; return error
: correction "`n" (a_tickCount-StartTime) ; return original
}
;#############
FEHLER(html) {
loop, parse,% html, `n, `r
if inStr(a_loopField,"Your client does not have permission to get URL")
res := xStr(a_loopField,,"<title>","</title>")
if res contains Error 403
{
filedelete, Error#403.html
fileappend,% html, Error#403.html
try run, Error#403.html
return res
}}
;#############
URLDownloadToVar(url){
hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
hObject.Open("GET",url)
hObject.Send()
return hObject.ResponseText
}
;#############
;- https://www.autohotkey.com/boards/viewtopic.php?f=6&t=74050
xStr(ByRef H, C:=0, B:="", E:="",ByRef BO:=1, EO:="", BI:=1, EI:=1, BT:="", ET:="") {
Local L, LB, LE, P1, P2, Q, N:="", F:=0 ; xStr v0.97 by SKAN on D1AL/D343 @ tiny.cc/xstr
Return SubStr(H,!(ErrorLevel:=!((P1:=(L:=StrLen(H))?(LB:=StrLen(B))?(F:=InStr(H,B,C&1,BO,BI))?F+(BT=N?LB
:BT):0:(Q:=(BO=1&&BT>0?BT+1:BO>0?BO:L+BO))>1?Q:1:0)&&(P2:=P1?(LE:=StrLen(E))?(F:=InStr(H,E,C>>1,EO=N?(F
?F+LB:P1):EO,EI))?F+LE-(ET=N?LE:ET):0:EO=N?(ET>0?L-ET+1:L+1):P1+EO:0)>=P1))?P1:L+1,(BO:=Min(P2,L+1))-P1)
}
;#############
EncodeDecodeURI(str, encode := true, component := true) { ; autor unbekannt
static Doc, JS
if !Doc {
Doc := ComObjCreate("htmlfile")
Doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
JS := Doc.parentWindow
( Doc.documentMode < 9 && JS.execScript() )
}
Return JS[ (encode ? "en" : "de") . "codeURI" . (component ? "Component" : "") ](str)
}
Hallo Just Me,
vielen Dank. Ich habe [c]URLDownloadToVar(url)[/c] getestet, musste aber feststellen das es in meinem Fall nicht funktioniert, schon bei der ersten Abfrage bekomme ich eine Fehlermeldung.
Es läuft aber auch ohne ganz toll
[attachment=0]06_26_23 @3_40_40.PNG[/attachment]
[code]
global startTime := a_tickCount
FileEncoding, UTF-8
; correction := "in münster und köln sind die strasen saubber"
correction := "wievieele Tankstelen gibtt es in münster und köln"
; correction := "dies ist ein fehlerfreier text, er wird im original zurück gegeben"
split := strSplit(function(correction),"`n","`r")
MsgBox % (split.1) ? (split.1 "`n`n" split.2 " mSec") : ""
exitapp
;#############
function(correction) {
url := "https://www.google.com/search?q=" (EncodeDecodeURI(correction,true, false)) "&ie=UTF-8"
toVar := true ; true erzeugt fehler 403
if toVar
{
html := URLDownloadToVar(url)
}else{
urlDownloadToFile,% url, tmp_html.html
FileRead, html, tmp_html.html
FileDelete, tmp_html.html
}
res=
loop, parse,% html, `n, `r
if inStr(a_loopField,">Ergebnisse f")
res := xStr(a_loopField,,"href=""/search?ie=UTF-8&q=","&spell=1")
res := strReplace(res,"+",a_space)
return (Result := EncodeDecodeURI(res,false, false))
? Result "`n" (a_tickCount-StartTime) ; return korriguert
: (error#403 := FEHLER(html))
? error#403 "`n" (a_tickCount-StartTime) ; return error
: correction "`n" (a_tickCount-StartTime) ; return original
}
;#############
FEHLER(html) {
loop, parse,% html, `n, `r
if inStr(a_loopField,"Your client does not have permission to get URL")
res := xStr(a_loopField,,"<title>","</title>")
if res contains Error 403
{
filedelete, Error#403.html
fileappend,% html, Error#403.html
try run, Error#403.html
return res
}}
;#############
URLDownloadToVar(url){
hObject:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
hObject.Open("GET",url)
hObject.Send()
return hObject.ResponseText
}
;#############
;- https://www.autohotkey.com/boards/viewtopic.php?f=6&t=74050
xStr(ByRef H, C:=0, B:="", E:="",ByRef BO:=1, EO:="", BI:=1, EI:=1, BT:="", ET:="") {
Local L, LB, LE, P1, P2, Q, N:="", F:=0 ; xStr v0.97 by SKAN on D1AL/D343 @ tiny.cc/xstr
Return SubStr(H,!(ErrorLevel:=!((P1:=(L:=StrLen(H))?(LB:=StrLen(B))?(F:=InStr(H,B,C&1,BO,BI))?F+(BT=N?LB
:BT):0:(Q:=(BO=1&&BT>0?BT+1:BO>0?BO:L+BO))>1?Q:1:0)&&(P2:=P1?(LE:=StrLen(E))?(F:=InStr(H,E,C>>1,EO=N?(F
?F+LB:P1):EO,EI))?F+LE-(ET=N?LE:ET):0:EO=N?(ET>0?L-ET+1:L+1):P1+EO:0)>=P1))?P1:L+1,(BO:=Min(P2,L+1))-P1)
}
;#############
EncodeDecodeURI(str, encode := true, component := true) { ; autor unbekannt
static Doc, JS
if !Doc {
Doc := ComObjCreate("htmlfile")
Doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
JS := Doc.parentWindow
( Doc.documentMode < 9 && JS.execScript() )
}
Return JS[ (encode ? "en" : "de") . "codeURI" . (component ? "Component" : "") ](str)
}
[/code]