지정된 Google 검색과 관련된 결과 수를 정렬 할 수있는 프로그램을 만들려고합니다. 매우 큰 테이블이 필요하므로 루프를 사용할 생각입니다. 내가 시도 할 때마다 "System.Windows.Markup.XamlParseException"로 인해 디버거가 충돌합니다.HttpWebRequest를 성공하지 않고 반복하려고 시도했습니다.
이 모든 방법은 단순히 같은 for 루프를 메인에 사용되는public long resultStat(string a)
{
var req = (HttpWebRequest)WebRequest.Create("https://www.google.ca/search?hl=fr&output=search&sclient=psy-ab&q=a" + a + "&btnK=");
using (req as IDisposable)
{
WebResponse rep = req.GetResponse();
Stream str = rep.GetResponseStream();
StreamReader rdr = new StreamReader(str);
string res = rdr.ReadToEnd();
rdr.Close();
//This is my code to get the number results (it works perfectly)
int index = res.IndexOf(">Environ");
int cond = 0;
string final = "";
try
{
while (res[++index] != '<')
{
if (cond-- == 0 && res[index] != '&')
{ final += res[index]; cond = 0; }
else if (res[index] == '&') cond = 5;
}
}
catch { return 0; }
string temp = "";
foreach (char i in final) if (i < 48 && i > 58) temp += i;
return Int64.Parse(temp);
}
}
: 나는 그것이 문제 알고
public void main()
{
//Other code
for (int i = 0; i < 3; i++) resultStat(i.ToString()); // For example
//Other code
}
최대한 빨리 루프를 언급, 또는 하나 명의 담당자로 낮추기로 인해 아무것도 잘못되지 않습니다. 나는 시도했다 :
HttpWebRequest(). Abort(); HttpWebRequest(). KeepAlive = false;
이
return int64.Parse (temp);를'long l = 0; Int64.TryParse (temp, out l); return l;'? – I4V
작동했지만 그 다음 각 결과를 목록에 저장하려고 시도했지만 다시 충돌했습니다 ... 팁을 주셔서 감사 드리며 다른 유사한 오류를 찾아 보겠습니다. – Hadron