コード例 #1
0
 private void visualButton4_Click(object sender, EventArgs e)
 {
     Method.Txt(dataGridView1);
 }
コード例 #2
0
        public void sougou()

        {
            string cookie = "CXID=D44C63D34623066DA36D11B4B82C488C; SUV=1518337255419884; SMAPUVID=1518337255419884; SUV=1801190926013760; IPLOC=CN3213; sct=1; SNUID=D67B2A4373761425DCE0226F733E2FA7; ad=zMGYjlllll2zYIpclllllVr1fv6lllllGq6poyllll9llllljZlll5@@@@@@@@@@; SUID=A10659313565860A5A6291B800040AA1; wP_w=544ebe2c0329~HXcgwyvcH_c_5BDcHXULrZvNyX9XwbmSJXPsNNDN3XNBbbDJbdNhb; activecity=%u5BBF%u8FC1%2C13168867%2C3999623%2C12; ho_co=";
            string url    = "http://map.sogou.com/EngineV6/search/json";

            string charset = "gb2312";

            try

            {
                string[] citys    = textBox1.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);
                string[] keywords = textBox2.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);



                int pages = 200;

                foreach (string city in citys)

                {
                    //搜索的城市和关键词都需要两次url编码

                    string city1    = System.Web.HttpUtility.UrlEncode(city, System.Text.Encoding.GetEncoding("utf-8"));
                    string cityutf8 = System.Web.HttpUtility.UrlEncode(city1, System.Text.Encoding.GetEncoding("utf-8"));
                    foreach (string keyword in keywords)

                    {
                        string keyword1    = System.Web.HttpUtility.UrlEncode(keyword, System.Text.Encoding.GetEncoding("utf-8"));
                        string keywordutf8 = System.Web.HttpUtility.UrlEncode(keyword1, System.Text.Encoding.GetEncoding("utf-8"));

                        for (int i = 1; i <= pages; i++)
                        {
                            string postData = "what=keyword%3A" + keywordutf8 + "&range=bound%3A00000000.5%2C0000000.5%2C99999999.5%2C9999999.5%3A0&othercityflag=1&appid=1361&thiscity=" + cityutf8 + "&lastcity=" + cityutf8 + "&userdata=3&encrypt=1&pageinfo=" + i + "%2C10&locationsort=0&version=7.0&ad=0&level=12&exact=1&type=&attr=&order=&submittime=0&resultTypes=poi&sort=0&reqid=1526008949358471&cb=parent.IFMS.search";

                            string html = Method.PostUrl(url, postData, cookie, charset);


                            MatchCollection TitleMatchs = Regex.Matches(html, @"""dataid"":""([\s\S]*?)""", RegexOptions.IgnoreCase);

                            ArrayList lists = new ArrayList();

                            foreach (Match NextMatch in TitleMatchs)
                            {
                                lists.Add(NextMatch.Groups[1].Value);
                            }
                            if (lists.Count == 0)  //当前页没有网址数据跳过之后的网址采集,进行下个foreach采集

                            {
                                break;
                            }

                            string tm1 = DateTime.Now.ToString();  //获取系统时间

                            textBox3.Text += tm1 + "-->正在采集" + city + "" + keyword + "第" + i + "页\r\n";


                            Application.DoEvents();
                            Thread.Sleep(100);



                            foreach (string poid in lists)

                            {
                                int index = this.dataGridView1.Rows.Add();


                                string Url1    = "http://map.sogou.com/poi/1_" + poid + ".htm";
                                string strhtml = GetUrl(Url1);


                                string title = @"""caption"":""([\s\S]*?)""";
                                string Rxg   = @"""phone"":""([\s\S]*?)""";
                                string Rxg1  = @"""address"":""([\s\S]*?)""";



                                MatchCollection titles  = Regex.Matches(strhtml, title);
                                MatchCollection tell    = Regex.Matches(strhtml, Rxg);
                                MatchCollection address = Regex.Matches(strhtml, Rxg1);

                                if (visualButton2.Text == "已停止")
                                {
                                    return;
                                }


                                foreach (Match match in titles)
                                {
                                    this.dataGridView1.Rows[index].Cells[0].Value = index;
                                    this.dataGridView1.Rows[index].Cells[1].Value = match.Groups[1].Value;
                                    this.dataGridView1.CurrentCell = this.dataGridView1.Rows[index].Cells[0];
                                }
                                foreach (Match match in tell)
                                {
                                    this.dataGridView1.Rows[index].Cells[2].Value += match.Groups[1].Value.Trim() + ",";
                                }
                                foreach (Match match in address)
                                {
                                    this.dataGridView1.Rows[index].Cells[3].Value = match.Groups[1].Value;
                                }


                                this.dataGridView1.Rows[index].Cells[4].Value = keyword;
                                this.dataGridView1.Rows[index].Cells[5].Value = city;


                                Application.DoEvents();
                                Thread.Sleep(500);   //内容获取间隔,可变量
                            }
                        }
                    }
                }
            }

            catch (System.Exception ex)
            {
                textBox3.Text = ex.ToString();
            }
        }
コード例 #3
0
 private void visualButton3_Click(object sender, EventArgs e)
 {
     Method.DataTableToExcel(Method.DgvToTable(dataGridView1), "Sheet1", true);
 }
コード例 #4
0
        public void map_360()

        {
            try

            {
                string[] citys    = textBox1.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);
                string[] keywords = textBox2.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);



                int pages = 100;

                foreach (string city in citys)

                {
                    string cityutf8 = System.Web.HttpUtility.UrlEncode(city, System.Text.Encoding.GetEncoding("utf-8"));
                    foreach (string keyword in keywords)

                    {
                        string keywordutf8 = System.Web.HttpUtility.UrlEncode(keyword, System.Text.Encoding.GetEncoding("utf-8"));
                        for (int i = 1; i <= pages; i++)



                        {
                            String Url = "https://ditu.so.com/app/pit?jsoncallback=jQuery18308131636402501483_1525852464213&keyword=" + keywordutf8 + "&cityname=" + cityutf8 + "&batch=" + i + "%2c" + (i + 1) + "%2c" + (i + 2) + "%2c" + (i + 3) + "%2c" + (i + 4) + "&number=10";



                            string html = Method.GetUrl(Url);


                            MatchCollection TitleMatchs = Regex.Matches(html, @"""pguid"":""([\s\S]*?)""", RegexOptions.IgnoreCase);

                            ArrayList lists = new ArrayList();

                            foreach (Match NextMatch in TitleMatchs)
                            {
                                lists.Add(NextMatch.Groups[1].Value);
                            }
                            if (lists.Count == 0)  //当前页没有网址数据跳过之后的网址采集,进行下个foreach采集

                            {
                                break;
                            }

                            string tm1 = DateTime.Now.ToString();  //获取系统时间

                            textBox3.Text += tm1 + "-->正在采集" + city + "" + keyword + "第" + i + "页\r\n";

                            Application.DoEvents();
                            Thread.Sleep(100);



                            foreach (string poid in lists)

                            {
                                int index = this.dataGridView1.Rows.Add();

                                string Url1    = "https://m.map.so.com/onebox/?type=detail&id=" + poid + "&mso_x=&mso_y=&d=mobile&src=map_wap&fields=movies_all";
                                string strhtml = Method.GetUrl(Url1);


                                string title = @"data_poi_name = ""([\s\S]*?)""";
                                string Rxg   = @"href=""tel:([\s\S]*?)""";
                                string Rxg1  = @"data_poi_address = ""([\s\S]*?)""";



                                MatchCollection titles  = Regex.Matches(strhtml, title);
                                MatchCollection tell    = Regex.Matches(strhtml, Rxg);
                                MatchCollection address = Regex.Matches(strhtml, Rxg1);

                                if (visualButton2.Text == "已停止")
                                {
                                    return;
                                }


                                foreach (Match match in titles)
                                {
                                    this.dataGridView1.Rows[index].Cells[0].Value = index;
                                    this.dataGridView1.Rows[index].Cells[1].Value = match.Groups[1].Value;
                                    this.dataGridView1.CurrentCell = this.dataGridView1.Rows[index].Cells[0];
                                }
                                foreach (Match match in tell)
                                {
                                    this.dataGridView1.Rows[index].Cells[2].Value += match.Groups[1].Value.Trim() + ",";
                                }
                                foreach (Match match in address)
                                {
                                    this.dataGridView1.Rows[index].Cells[3].Value = match.Groups[1].Value;
                                }


                                this.dataGridView1.Rows[index].Cells[4].Value = keyword;
                                this.dataGridView1.Rows[index].Cells[5].Value = city;



                                Application.DoEvents();
                                Thread.Sleep(500);   //内容获取间隔,可变量
                            }
                        }
                    }
                }
            }

            catch (System.Exception ex)
            {
                textBox3.Text = ex.ToString();
            }
        }
コード例 #5
0
        public void gaode()

        {
            try

            {
                string[] citys    = textBox1.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);
                string[] keywords = textBox2.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);



                int pages = 200;

                foreach (string city in citys)

                {
                    int citycode = gaodeCityId(city);
                    foreach (string keyword in keywords)

                    {
                        string keywordutf8 = System.Web.HttpUtility.UrlEncode(keyword, System.Text.Encoding.GetEncoding("utf-8"));

                        for (int i = 0; i <= pages; i++)
                        {
                            String Url = "http://m.amap.com/service/poi/keywords.json?pagenum=" + i + "&user_loc=undefined&geoobj=&city=" + citycode + "&keywords=" + keywordutf8;

                            string html = Method.GetUrl(Url);


                            MatchCollection TitleMatchs = Regex.Matches(html, @"""diner_flag"":([\s\S]*?),""id"":""([\s\S]*?)""", RegexOptions.IgnoreCase);

                            ArrayList lists = new ArrayList();

                            foreach (Match NextMatch in TitleMatchs)
                            {
                                lists.Add(NextMatch.Groups[2].Value);
                            }
                            if (lists.Count == 0)  //当前页没有网址数据跳过之后的网址采集,进行下个foreach采集

                            {
                                break;
                            }

                            string tm1 = DateTime.Now.ToString();  //获取系统时间

                            textBox3.Text += tm1 + "-->正在采集" + city + "" + keyword + "第" + i + "页\r\n";


                            Application.DoEvents();
                            Thread.Sleep(100);



                            foreach (string poid in lists)

                            {
                                int index = this.dataGridView1.Rows.Add();

                                string Url1    = "https://www.amap.com/detail/" + poid + "?citycode=" + citycode;
                                string strhtml = Method.GetUrl(Url1);


                                string title = @"<h4 class=""detail_title"">([\s\S]*?)</h4>";
                                string Rxg   = @"""telephone"":""([\s\S]*?)""";
                                string Rxg1  = @"""address"":""([\s\S]*?)""";



                                MatchCollection titles  = Regex.Matches(strhtml, title);
                                MatchCollection tell    = Regex.Matches(strhtml, Rxg);
                                MatchCollection address = Regex.Matches(strhtml, Rxg1);

                                if (visualButton2.Text == "已停止")
                                {
                                    return;
                                }


                                foreach (Match match in titles)
                                {
                                    this.dataGridView1.Rows[index].Cells[0].Value = index;
                                    this.dataGridView1.Rows[index].Cells[1].Value = match.Groups[1].Value;
                                    this.dataGridView1.CurrentCell = this.dataGridView1.Rows[index].Cells[0];
                                }
                                foreach (Match match in tell)
                                {
                                    this.dataGridView1.Rows[index].Cells[2].Value += match.Groups[1].Value.Trim() + ",";
                                }
                                foreach (Match match in address)
                                {
                                    this.dataGridView1.Rows[index].Cells[3].Value = match.Groups[1].Value;
                                }


                                this.dataGridView1.Rows[index].Cells[4].Value = keyword;
                                this.dataGridView1.Rows[index].Cells[5].Value = city;



                                Application.DoEvents();
                                Thread.Sleep(500);   //内容获取间隔,可变量
                            }
                        }
                    }
                }
            }

            catch (System.Exception ex)
            {
                textBox3.Text = ex.ToString();
            }
        }
コード例 #6
0
        public void txMap()

        {
            try

            {
                string[] citys = textBox1.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);


                string[] keywords = textBox2.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);

                int pages = 200;


                foreach (string city in citys)

                {
                    int cityid = getcityId(city + "市");  //获取 citycode;

                    foreach (string keyword in keywords)

                    {
                        for (int i = 0; i <= pages; i++)

                        {
                            String Url = "https://map.baidu.com/?newmap=1&reqflag=pcmap&biz=1&from=webmap&da_par=direct&pcevaname=pc4.1&qt=con&from=webmap&c=" + cityid + "&wd=" + keyword + "&wd2=&pn=" + i + "&nn=" + i + "0&db=0&sug=0&addr=0&&da_src=pcmappg.poi.page&on_gel=1&src=7&gr=3&l=13&tn=B_NORMAL_MAP&u_loc=13167420,3999298&ie=utf-8";

                            string html = Method.GetUrl(Url);


                            MatchCollection TitleMatchs = Regex.Matches(html, @"""primary_uid"":""([\s\S]*?)""", RegexOptions.IgnoreCase);

                            ArrayList lists = new ArrayList();

                            foreach (Match NextMatch in TitleMatchs)
                            {
                                lists.Add(NextMatch.Groups[1].Value);
                            }
                            if (lists.Count == 0)  //当前页没有网址数据跳过之后的网址采集,进行下个foreach采集

                            {
                                break;
                            }

                            string tm1 = DateTime.Now.ToString();  //获取系统时间

                            textBox3.Text += tm1 + "-->正在采集" + city + "" + keyword + "第" + i + "页\r\n";



                            JsonParser jsonParser = JsonConvert.DeserializeObject <JsonParser>(html);



                            foreach (Content content in jsonParser.Content)
                            {
                                int index = this.dataGridView1.Rows.Add();
                                this.dataGridView1.Rows[index].Cells[0].Value = index;
                                this.dataGridView1.Rows[index].Cells[1].Value = content.name;
                                this.dataGridView1.Rows[index].Cells[2].Value = content.tel;
                                this.dataGridView1.Rows[index].Cells[3].Value = content.addr;
                                this.dataGridView1.Rows[index].Cells[4].Value = keyword.Trim();
                                this.dataGridView1.Rows[index].Cells[5].Value = city;

                                this.dataGridView1.CurrentCell = this.dataGridView1.Rows[index].Cells[0];  //让datagridview滚动到当前行

                                if (visualButton2.Text == "已停止")
                                {
                                    return;
                                }
                            }



                            Application.DoEvents();
                            Thread.Sleep(100);   //内容获取间隔,可变量
                        }
                    }
                }
            }

            catch (System.Exception ex)
            {
                textBox1.Text = ex.ToString();
            }
        }
コード例 #7
0
        public void tengxun()

        {
            try

            {
                string[] citys    = textBox1.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);
                string[] keywords = textBox2.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);



                int pages = 250;

                foreach (string city in citys)

                {
                    string cityutf8 = System.Web.HttpUtility.UrlEncode(city, System.Text.Encoding.GetEncoding("utf-8"));
                    foreach (string keyword in keywords)

                    {
                        string keywordutf8 = System.Web.HttpUtility.UrlEncode(keyword, System.Text.Encoding.GetEncoding("utf-8"));
                        for (int i = 0; i <= pages; i++)


                        {
                            String Url = "http://map.qq.com/m/place/result/city=" + cityutf8 + "&word=" + keywordutf8 + "&bound=&page=" + i + "&cpos=&mode=list";

                            textBox3.Text = Url;
                            string html = Method.GetUrl(Url);


                            MatchCollection TitleMatchs = Regex.Matches(html, @"poid=([\s\S]*?)""", RegexOptions.IgnoreCase);

                            ArrayList lists = new ArrayList();

                            foreach (Match NextMatch in TitleMatchs)
                            {
                                lists.Add(NextMatch.Groups[1].Value);
                            }
                            if (lists.Count == 0)  //当前页没有网址数据跳过之后的网址采集,进行下个foreach采集

                            {
                                break;
                            }

                            string tm1 = DateTime.Now.ToString();  //获取系统时间

                            textBox3.Text += tm1 + "-->正在采集" + city + "" + keyword + "第" + i + "页\r\n";

                            Application.DoEvents();
                            Thread.Sleep(100);



                            foreach (string poid in lists)

                            {
                                int index = this.dataGridView1.Rows.Add();

                                string Url1    = "http://map.qq.com/m/detail/poi/poid=" + poid;
                                string strhtml = Method.GetUrl(Url1);


                                string title = @"<div class=""poiDetailTitle "">([\s\S]*?)</div>";
                                string Rxg   = @"<a href=""tel:([\s\S]*?)""";
                                string Rxg1  = @"span class=""poiDetailAddrTxt"">([\s\S]*?)</span>";



                                Match titles  = Regex.Match(strhtml, title);
                                Match tell    = Regex.Match(strhtml, Rxg);
                                Match address = Regex.Match(strhtml, Rxg1);

                                if (visualButton2.Text == "已停止")
                                {
                                    return;
                                }
                                if (tell.Groups[1].Value.Trim() != "")

                                {
                                    this.dataGridView1.Rows[index].Cells[0].Value = index;
                                    this.dataGridView1.Rows[index].Cells[1].Value = titles.Groups[1].Value;
                                    this.dataGridView1.CurrentCell = this.dataGridView1.Rows[index].Cells[0];

                                    this.dataGridView1.Rows[index].Cells[2].Value += tell.Groups[1].Value.Trim() + ",";

                                    this.dataGridView1.Rows[index].Cells[3].Value = address.Groups[1].Value;

                                    this.dataGridView1.Rows[index].Cells[4].Value = keyword;
                                    this.dataGridView1.Rows[index].Cells[5].Value = city;
                                }



                                Application.DoEvents();
                                Thread.Sleep(500);   //内容获取间隔,可变量
                            }
                        }
                    }
                }
            }

            catch (System.Exception ex)
            {
                textBox3.Text = ex.ToString();
            }
        }
コード例 #8
0
        public void baidu()

        {
            try

            {
                string[] citys = textBox1.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);


                string[] keywords = textBox2.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);

                int pages = 200;


                foreach (string city in citys)

                {
                    int cityid = getcityId(city + "市");  //获取 citycode;

                    foreach (string keyword in keywords)

                    {
                        for (int i = 0; i <= pages; i++)

                        {
                            int j = i - 1 > 0 ? i - 1 :0;

                            String Url = "https://map.baidu.com/?newmap=1&reqflag=pcmap&biz=1&from=webmap&da_par=direct&pcevaname=pc4.1&qt=con&from=webmap&c=" + cityid + "&wd=" + keyword + "&wd2=&pn=" + i + "&nn=" + j + "0&db=0&sug=0&addr=0&&da_src=pcmappg.poi.page&on_gel=1&src=7&gr=3&l=9.557396536572428&auth=Y%3DyW9VVIUF45OV8VGZCZb85Tzf4HRUPIuxHENxTzTzztComRB199Ay1uVt1GgvPUDZYOYIZuVt1cv3uVtGccZcuVtPWv3GuNtZComRdXmB1F234Q6W89AcEWe1GD8zv7u%40ZPuNtkB1FAprGnrFHQNWHaJ9caEmqQQDICfy9GUIsxA2wEjjg2JK&device_ratio=1&tn=B_NORMAL_MAP&u_loc=13177040,3994297&ie=utf-8&b=(12730445.232221898,4765711.534422691;13205701.20474543,4916707.941505569)&t=1547192932734";



                            string html = Method.GetUrl(Url);


                            MatchCollection TitleMatchs = Regex.Matches(html, @"""primary_uid"":""([\s\S]*?)""", RegexOptions.IgnoreCase);

                            ArrayList lists = new ArrayList();

                            foreach (Match NextMatch in TitleMatchs)
                            {
                                lists.Add(NextMatch.Groups[1].Value);
                            }
                            if (lists.Count == 0)  //当前页没有网址数据跳过之后的网址采集,进行下个foreach采集

                            {
                                break;
                            }

                            string tm1 = DateTime.Now.ToString();  //获取系统时间

                            textBox3.Text += tm1 + "-->正在采集" + city + "" + keyword + "第" + i + "页\r\n";



                            JsonParser jsonParser = JsonConvert.DeserializeObject <JsonParser>(html);



                            foreach (Content content in jsonParser.Content)
                            {
                                int index = this.dataGridView1.Rows.Add();
                                this.dataGridView1.Rows[index].Cells[0].Value = index;
                                this.dataGridView1.Rows[index].Cells[1].Value = content.name;
                                this.dataGridView1.Rows[index].Cells[2].Value = content.tel;
                                this.dataGridView1.Rows[index].Cells[3].Value = content.addr;
                                this.dataGridView1.Rows[index].Cells[4].Value = keyword.Trim();
                                this.dataGridView1.Rows[index].Cells[5].Value = city;

                                this.dataGridView1.CurrentCell = this.dataGridView1.Rows[index].Cells[0];  //让datagridview滚动到当前行

                                if (visualButton2.Text == "已停止")
                                {
                                    return;
                                }
                            }

                            Application.DoEvents();
                            Thread.Sleep(10);   //内容获取间隔,可变量
                        }
                    }
                }
            }

            catch (System.Exception ex)
            {
                ex.ToString();
            }
        }