username@email.com
2022-06-15 0e6d0e8975e92a6395d2d9f692edd5a7d0984c5a
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
using Crawler.sichuan;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Net.Http;
using System.Threading;
using zhengcaioa.Models;
 
namespace Crawler
{
    class Program
    {
        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();
 
            Console.WriteLine("Hello World!");
        }
 
        void Method1()
        {
            while (true)
            {
                string connection = @"server=.;database=WebCrawler;uid=sa;pwd=123456;";
                var dbContextOptionBuilder = new DbContextOptionsBuilder<WebCrawlerContext>();
                var cccontext = new WebCrawlerContext(dbContextOptionBuilder.UseSqlServer(connection).Options);
                //获取四川的政采数据
                sichuanoperation.operations(cccontext);
                Thread.CurrentThread.Join(1000*60*60*2);//阻止设定时间
            }
        }
 
        void Method2()
        {
            while (true)
            {
                Console.WriteLine(DateTime.Now.ToString() + "Method2_" + Thread.CurrentThread.ManagedThreadId.ToString());
                Thread.CurrentThread.Join(1000);//阻止设定时间
            }
        }
 
 
 
 
 
 
 
 
 
    }
}