username@email.com
2024-01-12 0e5c4a8e17dcefcc10b2507da61b099be12451d8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
using AngleSharp.Html.Parser;
using Crawler.sichuan;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using zhengcaioa.Models;
 
namespace Crawler
{
    class Program
    {
 
        //public static string connection = @"server=.;database=WebCrawler;uid=sa;pwd=123456;";
        //public static string connection1 = @"server=.;database=zhengcaioa;uid=sa;pwd=123456;";
        //public static string api_domain = "http://192.168.0.9:9200";
 
        public static string connection = @"server=172.26.97.184;database=WebCrawler;uid=sa;pwd=Za20222812;";
        public static string connection1 = @"server=172.26.97.184;database=zhengcaioa;uid=sa;pwd=Za20222812;";
        public static string api_domain = "http://172.26.97.184:9200";
        static void Main(string[] args)
        {
 
 
       
 
 
 
            ////FiBook fiBook = new FiBook();
            ////fiBook.Id = Guid.NewGuid().ToString();
            ////fiBook.RecStatus = "A";
            ////fiBook.Creater = "sdfdsfdsf";
            ////fiBook.Createtime = DateTime.Now;
            ////fiBook.Modifier = "sdfdsfdsf";
            ////fiBook.Modifytime = DateTime.Now;
            ////cccontext.FiBooks.Add(fiBook);
            ////cccontext.SaveChanges();
 
            //ZhengfuProject zhengfuProject = new ZhengfuProject();
 
            //logg.WriteLog("测试写日志");
 
            //ChromeOptions options = new ChromeOptions();
            //options.BinaryLocation = "C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe";
            ////options.AddArgument("--headless");
            ////options.AddArgument("blink-settings=imagesEnabled=false");
            ////_logger.LogInformation(address + "    开始解析");
            ////string chromeDriverDirectory = Microsoft.DotNet.PlatformAbstractions.ApplicationEnvironment.ApplicationBasePath;
            ////_logger.LogInformation(chromeDriverDirectory + "    当前项目路径");
            //try
            //{
            //    var driver = new ChromeDriver("C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\Application\\", options);
            //    driver.Navigate().GoToUrl("http://www.mof.gov.cn/gkml/xinxi/zhongyangbiaoxun/zhongyangzhaobiaogonggao/index_21.htm");
            //    //_logger.LogInformation(address + "    接着开始");
            //    while (true)
            //    {
            //        var content = driver.FindElement(By.ClassName("xwbd_lianbolistfrcon")).FindElements(By.TagName("li"));//FindElements(By.XPath("/html/body/section/div/div/div[2]/div/ul/li"));
 
 
            //        foreach (var item in content)
            //        {
            //            var link = item.FindElement(By.XPath("child::a")).GetAttribute("href");
            //            var title = item.Text;
            //            //if (!dic.ContainsKey(link))
            //            //    dic.Add(link, title);
            //        }
            //        //_logger.LogInformation("  开始翻页");
            //        //var nextPage = driver.FindElements(By.XPath("//*[@id='pagination']/ul/li"));
            //        var nextPage = driver.FindElement(By.ClassName("pagerji")).FindElements(By.TagName("span"));
            //        var boolll = false;
            //        foreach (var nextPagea in nextPage)
            //        {
            //            var linkk = nextPagea.FindElement(By.XPath("child::a")).GetAttribute("href");
            //            if (">".Equals(nextPagea.Text))
            //            {
            //                if (linkk.IndexOf("#") < 0)
            //                {
            //                    nextPagea.Click();
 
 
            //                    System.Threading.Thread.Sleep(1000); // 延时,避免找不到元素
            //                }
            //                else
            //                {
            //                    boolll = true;
            //                }
            //                break;
            //            }
 
            //            //var sss1 = nextPagea.ToString();
            //            //var sss2 = nextPagea.Text;
            //            //var sss = nextPagea.GetAttribute("class");
            //            //if (">".Equals(nextPagea.Text))
            //            //{
            //            //    if (!"disabled".Equals(nextPagea.GetAttribute("class")))
            //            //    {
            //            //        nextPagea.Click();
 
 
            //            //        System.Threading.Thread.Sleep(1000); // 延时,避免找不到元素
            //            //    }
            //            //    else
            //            //    {
            //            //        boolll = true;
            //            //    }
            //            //    break;
            //            //}
            //        }
            //        if (boolll)
            //        {
            //            break;
            //        }
 
            //    }
 
            //    driver.Quit();
            //}
            //catch (Exception ex)
            //{
            //    //_logger.LogInformation(ex.Message);
 
            //    //_logger.LogInformation(ex.StackTrace);
 
            //    //_logger.LogInformation(ex.ToString());
            //}
            //finally
            //{
 
            //}
 
 
 
 
            Program obj = new Program();
            //方法一:调用线程执行方法,在方法中实现死循环,每个循环Sleep设定时间
            Thread thread = new Thread(new ThreadStart(obj.Method1));
            thread.Start();
 
 
            Thread thread1 = new Thread(new ThreadStart(obj.Method2));
            thread1.Start();
 
 
            Thread thread2 = new Thread(new ThreadStart(obj.Method3));
            thread2.Start();
 
            Console.WriteLine("Hello World!");
        }
 
        void Method1()
        {
            while (true)
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                var dbContextOptionBuilder = new DbContextOptionsBuilder<WebCrawlerContext>();
                var cccontext = new WebCrawlerContext(dbContextOptionBuilder.UseSqlServer(connection).Options);
 
                var dbContextOptionBuilder1 = new DbContextOptionsBuilder<zhengcaioaContext>();
                var cccontext1 = new zhengcaioaContext(dbContextOptionBuilder1.UseSqlServer(connection1).Options);
 
                //获取四川的政采数据
                sichuanoperation.operations(cccontext, cccontext1);
                //Console.WriteLine("这个暂停");
                Thread.CurrentThread.Join(1000 * 60 * 60 * 2);//阻止设定时间
            }
        }
 
        void Method2()
        {
            while (true)
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                var dbContextOptionBuilder = new DbContextOptionsBuilder<WebCrawlerContext>();
                var cccontext = new WebCrawlerContext(dbContextOptionBuilder.UseSqlServer(connection).Options);
 
                var dbContextOptionBuilder1 = new DbContextOptionsBuilder<zhengcaioaContext>();
                var cccontext1 = new zhengcaioaContext(dbContextOptionBuilder1.UseSqlServer(connection1).Options);
 
                //获取四川的政采数据
                OldSichuanoperation.operations(cccontext, cccontext1);
                Thread.CurrentThread.Join(1000 * 60 * 60 * 2);//阻止设定时间
            }
        }
 
 
        void Method3()
        {
            while (true)
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
                var dbContextOptionBuilder = new DbContextOptionsBuilder<WebCrawlerContext>();
                var cccontext = new WebCrawlerContext(dbContextOptionBuilder.UseSqlServer(connection).Options);
 
                //var dbContextOptionBuilder1 = new DbContextOptionsBuilder<zhengcaioaContext>();
                //var cccontext1 = new zhengcaioaContext(dbContextOptionBuilder1.UseSqlServer(connection1).Options);
 
                //获取中国政采网的四川政采数据
                CcgpSichuanoperation.operations(cccontext);
                Thread.CurrentThread.Join(1000 * 60 * 10);//阻止设定时间
            }
        }
 
 
 
 
 
 
 
 
    }
}