private string GetMercadoTestUrl(string url, out string pyramid, out List <string> taskStrings, out string webType) { taskStrings = new List <string>(); pyramid = string.Empty; webType = string.Empty; if (string.IsNullOrEmpty(url)) { return(string.Empty); } url = AddDebugQuery(url); string pageSource = NetRequest.GetRequest(url); string htmlId = GetHtmlIdFromPageSource(pageSource); taskStrings = GetTaskStringFromPageSource(pageSource); if (taskStrings == null || taskStrings.Count == 0) { return(string.Empty); } GetPyramid(htmlId, out pyramid, out webType); string mercadoTestUrl = string.Format("{0}/mercadotest.{1}", AppConfig.Instance.GetMercadoDomain(pyramid), webType); return(mercadoTestUrl); }
private void ReadResponse(FileInfo file) { string site = file.Name.Replace(file.Extension, "").Replace("h_", ""); Logger logger = new Logger(file.Name); string taskDomain = AppConfig.Instance.GetTaskDomain(site); if (string.IsNullOrEmpty(taskDomain)) { return; } string[] lines = File.ReadAllLines(file.FullName); foreach (string line in lines) { string url = line.Trim(); if (string.IsNullOrEmpty(url)) { continue; } //if (AppConfig.Instance.IsPLPUrl(url)) continue; if (IsNotPlp(url)) { continue; } url = url.Replace(UrlUtility.GetDomain(url), taskDomain); url = UrlUtility.AddQuery(url, "debug", "Y"); string pathAndQuery = url.Replace(UrlUtility.GetDomain(url), "").TrimStart('/'); //int idx = pathAndQuery.IndexOfAny("/?".ToCharArray()); //string path = idx > 0 ? pathAndQuery.Substring(0, idx) : pathAndQuery; //if (hasReadUrl.Contains(path)) continue; Console.WriteLine(url); try { string response = NetRequest.GetRequest(url); if (response.IndexOf("Task String = ") >= 0) { logger.Log(url); //hasReadUrl.Add(path); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } logger.FlushToFile(); }
public void GetMercadoResponseWithMercadoTestPage(SpiderTask spiderTask) { List <string> taskStrings = new List <string>(); string pyramid, webType; string mercadoTestUrl = GetMercadoTestUrl(spiderTask.Url, out pyramid, out taskStrings, out webType); string postResponse = string.Empty; if (webType == "qs") { foreach (string taskString in taskStrings) { string postData = BuildMVCPostData(taskString); mercadoTestUrl = AddMercadoResultMethod(mercadoTestUrl); postResponse = NetRequest.PostRequest(mercadoTestUrl, postData); string mercadoXml = GetMercadoXmlFromPageSource(postResponse); SpiderTaskItem spiderTaskItem = new SpiderTaskItem(); spiderTaskItem.TaskString = taskString; spiderTaskItem.ResponseXml = mercadoXml; spiderTask.SpiderTaskItems.Add(spiderTaskItem); } } else { foreach (string taskString in taskStrings) { string testPageSource = NetRequest.GetRequest(mercadoTestUrl); string eventId = GetEventIdFromPageSource(testPageSource); string postData = BuildAspxPostData(eventId, taskString); postResponse = NetRequest.PostRequest(mercadoTestUrl, postData); string mercadoXml = GetMercadoXmlFromPageSource(postResponse); SpiderTaskItem spiderTaskItem = new SpiderTaskItem(); spiderTaskItem.TaskString = taskString; spiderTaskItem.ResponseXml = mercadoXml; spiderTask.SpiderTaskItems.Add(spiderTaskItem); } } }