示例#1
0
        public void ParsePage(string source, keydowno_backyard_farmerEntities db)
        {
            int start = source.IndexOf("<div id=\"searchresults\">");
            int end = source.IndexOf("<script type=\"text/javascript\">", start);

            string substr = source.Substring(start, end - start);

            string[] stringSeparators = new string[] { "http://rdf.data-vocabulary.org/" }; // separate the different vetshops
            string[] htmlText;
            htmlText = substr.Split(stringSeparators, StringSplitOptions.None); //string with vetshops

            // coords parser start here

            int pointsTemp = source.IndexOf("var point");
            int pointsStart = source.IndexOf(";", pointsTemp);
            int pointsEnd = source.IndexOf("map.bestFit");
            string pointsSubstr = source.Substring(pointsStart, pointsEnd - pointsStart);

            string[] pointSeparator = new string[] { "MQA.LatLng" }; // separate all the coordinates
            string[] pointsResult;
            pointsResult = pointsSubstr.Split(pointSeparator, StringSplitOptions.None); // string with coordinates

               // return htmlText[2];

            for (int i = 1; i < htmlText.Length - 1; i++)
            {
                Vet doctor = new Vet();
                VetsWorkingHour workHours = new VetsWorkingHour();

                doctor.Name = ParseData(htmlText[i], "v:name");
                doctor.Address = ParseData(htmlText[i], "v:street-address");
                doctor.City = ParseData(htmlText[i], "v:locality");
                doctor.State = ParseData(htmlText[i], "v:region");
                doctor.Zip = ParseData(htmlText[i], "v:postal-code");
                doctor.Phone = ParseData(htmlText[i], "v:tel");
                doctor.Image = GetImg(htmlText[i]);

                doctor.Latitude = double.Parse(ParseCoordinates(pointsResult[i])[0]);
                doctor.Longitude = double.Parse(ParseCoordinates(pointsResult[i])[1]);

                workHours.Monday = ParseWorkingHours(htmlText[i], "Mon");
                workHours.Tuesday = ParseWorkingHours(htmlText[i], "Tue");
                workHours.Wednesday = ParseWorkingHours(htmlText[i], "Wed");
                workHours.Thursday = ParseWorkingHours(htmlText[i], "Thu");
                workHours.Friday = ParseWorkingHours(htmlText[i], "Fri");
                workHours.Saturday = ParseWorkingHours(htmlText[i], "Sat");
                workHours.Sunday = ParseWorkingHours(htmlText[i], "Sun");

                db.Vets.Add(doctor);
                workHours.Id = doctor.Id;
                db.VetsWorkingHours.Add(workHours);
                db.SaveChanges();
            }
        }
示例#2
0
        public void ParsePage(string source, keydowno_backyard_farmerEntities db, string city, string state)
        {
            while (source.IndexOf("// Set up the InfoWindow for this marker.") != -1)
            {
                int start = source.IndexOf("// Set up the InfoWindow for this marker.");
                int end = source.IndexOf("markerArray[maNum] = curMarker;", start);

                string vetInfo = source.Substring(start, end - start);

                source = source.Substring(end);

                //vet phone
                start = vetInfo.IndexOf("<a href=\"tel://");
                end = vetInfo.IndexOf("\">", start);
                string vetPhone = vetInfo.Substring(start + "<a href=\"tel://".Length, end - start - "<a href=\"tel://".Length);
                vetInfo = vetInfo.Substring(end);

                //vet name
                start = vetInfo.IndexOf("curMarker = createMarker(\"");
                end = vetInfo.IndexOf("\",", start);
                string vetName = vetInfo.Substring(start + "curMarker = createMarker(\"".Length, end - start - "curMarker = createMarker(\"".Length);
                vetInfo = vetInfo.Substring(end);

                //vet address
                start = vetInfo.IndexOf("'', \"\", \"");
                end = vetInfo.IndexOf("\",", start + "'', \"\", \"".Length);
                string vetAddress = vetInfo.Substring(start + "'', \"\", \"".Length, end - start - "'', \"\", \"".Length);
                vetInfo = vetInfo.Substring(end);

                string vetZip = vetAddress.Substring(vetAddress.LastIndexOf(' ') + 1);
                try
                {
                    int testZip = int.Parse(vetZip);
                }
                catch (Exception)
                {
                    vetZip = "";
                }

                //vet longitude (strange, but longitude is first here)
                start = vetInfo.IndexOf("'");
                end = vetInfo.IndexOf("',", start);
                string vetLongitude = vetInfo.Substring(start + "'".Length, end - start - "'".Length);
                vetInfo = vetInfo.Substring(end + "',".Length);

                //vet latitude
                start = vetInfo.IndexOf("'");
                end = vetInfo.IndexOf("')", start);
                string vetLatitude = vetInfo.Substring(start + "'".Length, end - start - "'".Length);
                vetInfo = vetInfo.Substring(end);

                Vet doctor = new Vet();
                doctor.Name = vetName;
                doctor.Address = vetAddress;
                doctor.City = city;
                doctor.State = state;
                doctor.Zip = vetZip;
                doctor.Phone = vetPhone;

                doctor.Latitude = double.Parse(vetLatitude, CultureInfo.InvariantCulture);
                doctor.Longitude = double.Parse(vetLongitude, CultureInfo.InvariantCulture);
                db.Vets.Add(doctor);
                db.SaveChanges();
            }
        }
示例#3
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            keydowno_backyard_farmerEntities db = new keydowno_backyard_farmerEntities();
            List<string> codes = db.TempZipCodes.Select(x => x.Zip).ToList();

            foreach (var code in codes)
            {
                try
                {
                Thread.Sleep(1000);
                string zip = code.ToString();
                string source = PerformRequest(zip);
                ParsePage(source, db);
                int numPages = GetPagesNum(source);
                Thread.Sleep(1000);

                var a = db.TempZipCodes.Where(x => x.Zip == code).First();
                a.Parsed = true;
                db.SaveChanges();
                }
                catch (Exception)
                {

                    continue;
                }
            }
        }