-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.xml
202 lines (177 loc) · 27.9 KB
/
search.xml
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
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>Enigma加密解密(Advanced Engima Cracking)</title>
<url>/2021/03/27/Enigma%E5%8A%A0%E5%AF%86%E8%A7%A3%E5%AF%86-Advanced-Engima-Cracking/</url>
<content><![CDATA[<p>模拟破解engima的过程。</p>
<p>实际编程不算很难,主要是理解上出了很多次岔子,上课没有好好听啊。</p>
<span id="more"></span>
<h2 id="部件组成"><a href="#部件组成" class="headerlink" title="部件组成"></a>部件组成</h2><p>已知</p>
<ol>
<li>Plugboard(插线板)</li>
<li>RingSetting(齿轮内部设置)</li>
<li>CipherText(密文)</li>
<li>Word</li>
<li>最左齿轮编号</li>
</ol>
<p>求解:</p>
<ol>
<li>MessageKey</li>
<li>PlainText(明文)</li>
<li>RotorNum(齿轮编号)</li>
</ol>
<h2 id="加密原理"><a href="#加密原理" class="headerlink" title="加密原理"></a>加密原理</h2><p>先给出3个齿轮的外部状态(明文) 和真正接下来使用的齿轮状态(密文),共六个字母。用Enigama机在该外部状态下输入密文从而得到对应真正齿轮状态的明文。</p>
<p>接下来用真正齿轮状态(MessageKey)输入密文字符串得到对应明文或输入明文字符串得到密文。</p>
<p>对于输入字母经过以下5个阶段</p>
<ol>
<li>变为接线板对应字母</li>
<li>从右到左经过3个齿轮(根据当前MessageKey得到输出)<ol>
<li>进入齿轮的不是当前变化后的字母,而是Ring Setting后的。即从右往左输入先加delta,从左往右输出减delta。其中delta为当前message-key-ringkey(转子外-内)</li>
<li>当按下某个键位时,对字母加密的是齿轮转了一下的状态</li>
</ol>
</li>
<li>反射板(两两对应字母)</li>
<li>从左到右再经过3个齿轮</li>
<li>变为接线板对应字母</li>
</ol>
<p>对于MessageKey的处理</p>
<ol>
<li>每按键1次转子只转动一次</li>
<li>特殊情况:double stepping: 可能会出现两个或三个齿轮共同旋转</li>
<li>注意RingSetting是固定的</li>
</ol>
<h3 id="实例"><a href="#实例" class="headerlink" title="实例"></a>实例</h3><figure class="highlight c++"><table><tr><td class="code"><pre><span class="line"><span class="keyword">char</span> reflector[]=<span class="string">"YRUHQSLDPXNGOKMIEBFZCWVJAT"</span>; </span><br><span class="line"><span class="keyword">char</span> rotor_table[<span class="number">5</span>][<span class="number">27</span>] = </span><br><span class="line">{</span><br><span class="line"><span class="string">"EKMFLGDQVZNTOWYHXUSPAIBRCJ"</span>,</span><br><span class="line"><span class="string">"AJDKSIRUXBLHWTMCQGZNPYFVOE"</span>,</span><br><span class="line"><span class="string">"BDFHJLCPRTXVZNYEIWGAKMUSQO"</span>,</span><br><span class="line"><span class="string">"ESOVPZJAYQUIRHXLNFTGKDCMWB"</span>,</span><br><span class="line"><span class="string">"VZBRGITYUPSDNHLXAWMJQOFECK"</span></span><br><span class="line">};</span><br><span class="line"><span class="keyword">char</span> step_char[<span class="number">5</span>]=<span class="string">"RFWKA"</span>; <span class="comment">// Royal Flags Wave Kings Above</span></span><br><span class="line">MessageKey: CRZ</span><br><span class="line">Ring: TIP</span><br><span class="line">Delta: <span class="number">-17</span>,<span class="number">9</span>,<span class="number">10</span></span><br><span class="line">C-D</span><br><span class="line">Round <span class="number">1</span>:</span><br><span class="line"> D+<span class="number">10</span> = N->H<span class="number">-10</span> = X</span><br><span class="line">Round <span class="number">2</span>:</span><br><span class="line"> X+<span class="number">9</span> = G->R<span class="number">-9</span> = I</span><br><span class="line">Round <span class="number">3</span>:</span><br><span class="line"> I<span class="number">-17</span> = R->U+<span class="number">17</span> = L</span><br><span class="line">Reflect:</span><br><span class="line"> L-G</span><br><span class="line">Round <span class="number">31</span>:</span><br><span class="line"> G+<span class="number">17</span> = X->Q<span class="number">-17</span> = Z</span><br><span class="line"> N+<span class="number">17</span> = E->A<span class="number">-17</span> = J</span><br><span class="line">Round <span class="number">21</span>:</span><br><span class="line"> Z<span class="number">-9</span> = Q->Q+<span class="number">9</span> = Z</span><br><span class="line"> J<span class="number">-9</span> = A->A+<span class="number">9</span> = J</span><br><span class="line">Round <span class="number">11</span>:</span><br><span class="line"> Z<span class="number">-10</span> = P->J+<span class="number">10</span> = T</span><br><span class="line"> J<span class="number">-10</span> = Z->B+<span class="number">10</span> = L</span><br><span class="line">L-M</span><br></pre></td></tr></table></figure>
<h2 id="解密原理"><a href="#解密原理" class="headerlink" title="解密原理"></a>解密原理</h2><p>遍历,暴力破解。</p>
<p>依次遍历所有的Rotor_num、MessageKey和密文字符串可能,若出现Word子串,则为正确的。(由于数据设置,只有一个含有子串的匹配项)</p>
<h2 id="踩坑"><a href="#踩坑" class="headerlink" title="踩坑"></a>踩坑</h2><ul>
<li>一开始看老师的课件以为反过来从右到左时变为先减Δ,再加Δ,实际还是原来的,不需要考虑变化。</li>
<li>delta就是可以是负数,不需要考虑对26取模</li>
<li>MessageKey不是没过一个转子对对应的转子进行+1取模操作,而是根据按键</li>
<li>Double Setpping有一种状态漏了对最右边转子旋转</li>
</ul>
<h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><p>byy老师的回放视频</p>
]]></content>
<categories>
<category>密码学</category>
</categories>
<tags>
<tag>密码学</tag>
<tag>Enigma</tag>
<tag>作业</tag>
</tags>
</entry>
<entry>
<title>Hexo搭建——关于我踩的坑</title>
<url>/2021/03/26/Hexo%E6%90%AD%E5%BB%BA%E2%80%94%E2%80%94%E5%85%B3%E4%BA%8E%E6%88%91%E8%B8%A9%E7%9A%84%E5%9D%91/</url>
<content><![CDATA[<p>第一次搭个人博客,虽然看了不少教程,还是踩了超多的坑。这里总结一下。</p>
<span id="more"></span>
<h2 id="开始搭建"><a href="#开始搭建" class="headerlink" title="开始搭建"></a>开始搭建</h2><p>我选的是Next主题,原因有两个:一是够好看,二是教程够多。</p>
<p>没想到这么多的教程还是翻车搞了整整一晚上加早上。</p>
<h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><p>总结我踩过的坑,第一恨的就是哪些被搬来搬去从个人网站到博客园再到CSDN的可恶搬运党了。所以说还是要看官方文档。比如搭建还是看<a href="https://hexo.io/zh-cn/docs/index.html">Hexo官方文档</a>,主题配置还是看<a href="https://theme-next.js.org/page/2/">Next主题官方文档</a>。</p>
]]></content>
<categories>
<category>Hexo</category>
</categories>
<tags>
<tag>Hexo</tag>
<tag>Blog</tag>
</tags>
</entry>
<entry>
<title>Hello World</title>
<url>/2021/03/26/hello-world/</url>
<content><![CDATA[<p>Welcome to <a href="https://hexo.io/">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues">GitHub</a>.</p>
<span id="more"></span>
<h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">$ hexo new <span class="string">"My New Post"</span></span><br></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/writing.html">Writing</a></p>
<h3 id="Run-server"><a href="#Run-server" class="headerlink" title="Run server"></a>Run server</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">$ hexo server</span><br></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/server.html">Server</a></p>
<h3 id="Generate-static-files"><a href="#Generate-static-files" class="headerlink" title="Generate static files"></a>Generate static files</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">$ hexo generate</span><br></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/generating.html">Generating</a></p>
<h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">$ hexo deploy</span><br></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/one-command-deployment.html">Deployment</a></p>
]]></content>
</entry>
<entry>
<title>基于python+selenium+tasksch实现的PTA每日自动打卡</title>
<url>/2021/05/19/%E5%9F%BA%E4%BA%8Epython-selenium-tasksch%E5%AE%9E%E7%8E%B0%E7%9A%84PTA%E6%AF%8F%E6%97%A5%E8%87%AA%E5%8A%A8%E6%89%93%E5%8D%A1/</url>
<content><![CDATA[<p>每次考试周前都要给PTA充钱买卷子,花费甚多,内心不安。为了减少用钻石付费金币的惨剧,写了个PTA自动打卡的程序。</p>
<p>编程语言为python,参考了前辈的代码,利用selenium实现。</p>
<span id="more"></span>
<p>由于签到需要先登录,所以用代码获取登录状态下的cookie后,cookie直接实现登录网页。然后用xpath定位签到按钮,执行一次click,完成签到。</p>
<h2 id="操作"><a href="#操作" class="headerlink" title="操作"></a>操作</h2><h3 id="准备"><a href="#准备" class="headerlink" title="准备"></a>准备</h3><ul>
<li>一台24小时运行的云服务器</li>
<li>对应py脚本</li>
</ul>
<h4 id="Windows系统"><a href="#Windows系统" class="headerlink" title="Windows系统"></a>Windows系统</h4><p>需要先行下载 python 与 selenium,可以使用pip。</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">pip install selenium</span><br></pre></td></tr></table></figure>
<p>高版本的 selenium 需要配合 geckodriver 使用,点击<a href="https://github.com/mozilla/geckodriver/releases">这里</a>自行下载对应版本并添加环境变量。</p>
<p>替换py文件中的绝对路径为对应本机的位置。</p>
<p>先运行login.py,设置断点在 <code>dictCookies = driver.get_cookies()</code> 处,在弹出的页面登录,登录成功后继续运行,得到登录cookie。</p>
<p>尝试运行check.py,由于签到按钮只可按动一次,推荐注释掉57行,不注释58行进行验证。</p>
<h4 id="Linux系统"><a href="#Linux系统" class="headerlink" title="Linux系统"></a>Linux系统</h4><p>见<a href="/2021/05/20/Linux%E4%B8%8B%E8%BD%BDselenium-chrome-chrome-driver/" title="Linux下载selenium+chrome+chrome driver">Linux下载selenium+chrome+chrome driver</a>一文</p>
<h3 id="利用-bat-tasksch-自动打卡"><a href="#利用-bat-tasksch-自动打卡" class="headerlink" title="利用 bat+tasksch 自动打卡"></a>利用 bat+tasksch 自动打卡</h3><p>打开记事本,输入并保存为 <code>Run_PTA_Check.bat</code> </p>
<figure class="highlight cmd"><table><tr><td class="code"><pre><span class="line">"python.exe所在路径,如C:\Python39\python.exe" "check.py所在路径,如D:\Code\check.py" </span><br></pre></td></tr></table></figure>
<p>接下来利用windows自带的任务计划程序实现。</p>
<p>win+R,输入taskschd.msc打开任务计划程序</p>
<img src="/2021/05/19/%E5%9F%BA%E4%BA%8Epython-selenium-tasksch%E5%AE%9E%E7%8E%B0%E7%9A%84PTA%E6%AF%8F%E6%97%A5%E8%87%AA%E5%8A%A8%E6%89%93%E5%8D%A1/PTA1.png" class="" title="This is an example image">
<p>创建基本任务</p>
<img src="/2021/05/19/%E5%9F%BA%E4%BA%8Epython-selenium-tasksch%E5%AE%9E%E7%8E%B0%E7%9A%84PTA%E6%AF%8F%E6%97%A5%E8%87%AA%E5%8A%A8%E6%89%93%E5%8D%A1/PTA2.png" class="" title="This is an example image">
<p>名称随便输入,自己记得就好。触发器设置为每天。操作设置为启动程序。</p>
<img src="/2021/05/19/%E5%9F%BA%E4%BA%8Epython-selenium-tasksch%E5%AE%9E%E7%8E%B0%E7%9A%84PTA%E6%AF%8F%E6%97%A5%E8%87%AA%E5%8A%A8%E6%89%93%E5%8D%A1/PTA3.png" class="" title="This is an example image">
<p>程序或脚本处输出.bat文件路径,点击下一步并完成。</p>
<img src="/2021/05/19/%E5%9F%BA%E4%BA%8Epython-selenium-tasksch%E5%AE%9E%E7%8E%B0%E7%9A%84PTA%E6%AF%8F%E6%97%A5%E8%87%AA%E5%8A%A8%E6%89%93%E5%8D%A1/PTA4.png" class="" title="This is an example image">
<h2 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h2><p>login.py</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="string">'''</span></span><br><span class="line"><span class="string">@Description: 得到登录cookie, 保存为cookie_pintia.json</span></span><br><span class="line"><span class="string">@Author: ykiZheng</span></span><br><span class="line"><span class="string">@Date: 2021/5/19</span></span><br><span class="line"><span class="string">'''</span></span><br><span class="line"><span class="keyword">import</span> json</span><br><span class="line"><span class="keyword">from</span> selenium <span class="keyword">import</span> webdriver</span><br><span class="line"></span><br><span class="line">url = <span class="string">'https://pintia.cn/market'</span></span><br><span class="line">FireFox_options = webdriver.FirefoxOptions()</span><br><span class="line">FireFox_options.add_argument(<span class="string">'--headless'</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 将 'C://geckodriver' 替换为本机geckodriver所在位置</span></span><br><span class="line">driver = webdriver.Firefox(executable_path=<span class="string">'C://geckodriver'</span>,service_log_path=<span class="string">""</span>) <span class="comment"># 打开运行 </span></span><br><span class="line">driver.get(url)</span><br><span class="line"></span><br><span class="line">dictCookies = driver.get_cookies() <span class="comment">#获得所有cookie信息(返回是字典)</span></span><br><span class="line"><span class="built_in">print</span>(dictCookies)</span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">type</span>(dictCookies))</span><br><span class="line">jsonCookies = json.dumps(dictCookies) <span class="comment">#dumps是将dict转化成str格式</span></span><br><span class="line"><span class="built_in">print</span>(jsonCookies)</span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">type</span>(jsonCookies))</span><br><span class="line"><span class="comment"># 登录完成后,将cookies保存到本地文件</span></span><br><span class="line"><span class="keyword">with</span> <span class="built_in">open</span>(<span class="string">"cookies_pintia.json"</span>, <span class="string">"w"</span>) <span class="keyword">as</span> fp:</span><br><span class="line"> fp.write(jsonCookies)</span><br></pre></td></tr></table></figure>
<p>check.py</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="string">'''</span></span><br><span class="line"><span class="string">@Description: 利用cookie实现PTA自动打卡</span></span><br><span class="line"><span class="string">@Author: ykiZheng</span></span><br><span class="line"><span class="string">@Date: 2021/5/19</span></span><br><span class="line"><span class="string">'''</span></span><br><span class="line"><span class="keyword">import</span> json</span><br><span class="line"><span class="keyword">from</span> selenium <span class="keyword">import</span> webdriver<span class="comment">#导入库</span></span><br><span class="line"><span class="keyword">import</span> time</span><br><span class="line"></span><br><span class="line">name_stu = [</span><br><span class="line"> <span class="string">'我的大号'</span>,</span><br><span class="line"> <span class="string">'我的小号'</span></span><br><span class="line">]</span><br><span class="line">str_out = [] <span class="comment"># 将要写入文件的文本</span></span><br><span class="line"><span class="comment"># 初始化selenium</span></span><br><span class="line">url = <span class="string">'https://pintia.cn/market'</span></span><br><span class="line">FireFox_options = webdriver.FirefoxOptions()</span><br><span class="line">FireFox_options.add_argument(<span class="string">'--headless'</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 选择运行模式</span></span><br><span class="line"><span class="comment"># 将 'C://geckodriver' 替换为本机geckodriver所在位置</span></span><br><span class="line">driver = webdriver.Firefox(executable_path=<span class="string">'C://geckodriver'</span>,service_log_path=<span class="string">""</span>) <span class="comment"># 打开运行</span></span><br><span class="line"><span class="comment"># driver = webdriver.FireFox(chrome_options=chrome_options) # 静默运行</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># driver.maximize_window() # 最大化网页</span></span><br><span class="line">driver.get(url)</span><br><span class="line">driver.delete_all_cookies() <span class="comment"># 删除所有cookie信息</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 将 'D://Code/cookies_pintia.json' 替换为本机cookies_pintia.json所在路径</span></span><br><span class="line"><span class="keyword">with</span> <span class="built_in">open</span>(<span class="string">'D://Code/cookies_pintia.json'</span>, <span class="string">'r'</span>, encoding=<span class="string">'utf-8'</span>) <span class="keyword">as</span> f:</span><br><span class="line"> listCookies = json.loads(f.read()) <span class="comment">#loads是将str转化成dict格式</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> cookie <span class="keyword">in</span> listCookies:</span><br><span class="line"> driver.add_cookie({ <span class="comment">#此处模仿之前生成的cookies_pintia.json的格式写即可,要用单引号,因为已经转成dict格式了</span></span><br><span class="line"> <span class="string">'domain'</span>: <span class="string">'.pintia.cn'</span>,</span><br><span class="line"> <span class="string">'name'</span>: cookie[<span class="string">'name'</span>],</span><br><span class="line"> <span class="string">'value'</span>: cookie[<span class="string">'value'</span>],</span><br><span class="line"> <span class="string">'path'</span>: <span class="string">'/'</span>,</span><br><span class="line"> <span class="string">'expires'</span>: <span class="literal">None</span></span><br><span class="line"> })</span><br><span class="line"></span><br><span class="line">driver.get(url)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 当前时间</span></span><br><span class="line">tm_year = time.localtime().tm_year</span><br><span class="line">tm_mon = time.localtime().tm_mon</span><br><span class="line">tm_day = time.localtime().tm_mday</span><br><span class="line">tm_hour = time.localtime().tm_hour</span><br><span class="line">tm_min = time.localtime().tm_min</span><br><span class="line">tm_sec = time.localtime().tm_sec</span><br><span class="line">str_time = <span class="string">'\n'</span> + <span class="built_in">str</span>(tm_year) + <span class="string">'年'</span>+<span class="built_in">str</span>(tm_mon) + <span class="string">'月'</span> +<span class="built_in">str</span>(tm_day) + <span class="string">'日'</span> + <span class="built_in">str</span>(tm_hour) + <span class="string">'时'</span> + <span class="built_in">str</span>(tm_min) + <span class="string">'分'</span> + <span class="built_in">str</span>(tm_sec) + <span class="string">'秒\n'</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># time.sleep(1.5)</span></span><br><span class="line"><span class="keyword">try</span>:</span><br><span class="line"> <span class="comment"># 签到</span></span><br><span class="line"> element = driver.find_element_by_xpath(<span class="string">'/html/body/div/div[1]/header/div/div/button'</span>)</span><br><span class="line"> <span class="comment">#充值-用来测试能否找到组件</span></span><br><span class="line"> <span class="comment">#element = driver.find_element_by_xpath('/html/body/div/div[1]/header/div/div/a[1]')</span></span><br><span class="line"> element.click()</span><br><span class="line"> str_out.append(name_stu[<span class="number">0</span>] +<span class="string">'签到成功\n'</span>)</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'签到成功'</span>)</span><br><span class="line"><span class="keyword">except</span>:</span><br><span class="line"> str_out.append(name_stu[<span class="number">0</span>] +<span class="string">'未找到组件\n'</span>)</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'未找到组件'</span>)</span><br><span class="line"><span class="comment"># time.sleep(1)</span></span><br><span class="line"></span><br><span class="line">f.close()</span><br><span class="line"></span><br><span class="line">driver.close()</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 记录日志</span></span><br><span class="line"><span class="built_in">print</span>(str_time + <span class="built_in">str</span>(str_out) + <span class="string">'正在将结果写入文件\n'</span>)</span><br><span class="line"><span class="comment"># 将 'D:\Code\PTA签到\out.txt' 替换为想要的本机log路径</span></span><br><span class="line">out = <span class="built_in">open</span>(<span class="string">r'D:\Code\PTA签到\out.txt'</span>, <span class="string">'a'</span>, encoding=<span class="string">'utf-8'</span>)</span><br><span class="line">out.write(str_time)</span><br><span class="line">out.writelines(str_out)</span><br><span class="line">out.close()</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'文件写入完成\n'</span>)</span><br></pre></td></tr></table></figure>
<h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><p><a href="http://www.tyu.zone/index.php/2020/10/17/%E5%9F%BA%E4%BA%8Epythonselenium%E5%AE%9E%E7%8E%B0pta%E8%87%AA%E5%8A%A8%E6%89%93%E5%8D%A1/">基于python+selenium实现pta自动打卡</a></p>
]]></content>
<tags>
<tag>Python</tag>
<tag>selenium</tag>
</tags>
</entry>
<entry>
<title>Linux下载selenium+chrome+chrome driver</title>
<url>/2021/05/20/Linux%E4%B8%8B%E8%BD%BDselenium-chrome-chrome-driver/</url>
<content><![CDATA[<p>自动签到等脚本运行往往需要部署在云服务器上。由于本人的服务器为 Linux系统,接下来就演示如何部署签到系统所需的selenium+chrome+chrome driver的下载。</p>
<span id="more"></span>
<h2 id="下载python-selenium"><a href="#下载python-selenium" class="headerlink" title="下载python+selenium"></a>下载python+selenium</h2><p><a href="https://www.cnblogs.com/kimyeee/p/7250560.html">Linux下安装Python3.6和第三方库</a></p>
<p>按这个做</p>
<p>然后就可以用pip下载了</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">pip3 install selenium</span><br></pre></td></tr></table></figure>
<h2 id="下载chrome-chrome-driver"><a href="#下载chrome-chrome-driver" class="headerlink" title="下载chrome+chrome driver"></a>下载chrome+chrome driver</h2><ol>
<li>下载chrome浏览器,headless版本</li>
</ol>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">sudo apt-get install libxss1 libappindicator1 libindicator7</span><br><span class="line">wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb</span><br><span class="line">sudo dpkg -i google-chrome*.deb # Might show "errors", fixed by next line</span><br><span class="line">sudo apt-get install -f</span><br></pre></td></tr></table></figure>
<ol start="2">
<li>查看chrome版本,查看对应版本号,本机为 90.0.4430</li>
</ol>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">google-chrome --version</span><br></pre></td></tr></table></figure>
<ol start="3">
<li>下载对应版本的chrome driver,本机为 90.0.4430.24,故在<a href="http://npm.taobao.org/mirrors/chromedriver/%E9%80%89%E6%8B%A9%E5%AF%B9%E5%BA%94%E7%9A%84%E7%89%88%E6%9C%AC%EF%BC%8C%E4%BD%BF%E7%94%A8wget%E4%B8%8B%E8%BD%BD">http://npm.taobao.org/mirrors/chromedriver/选择对应的版本,使用wget下载</a></li>
</ol>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">wget http://npm.taobao.org/mirrors/chromedriver/<span class="number">90.0</span><span class="number">.4430</span><span class="number">.24</span>/ <span class="comment">#注意将90.0.4430.24替换为你的chrome对应的chromedriver版本</span></span><br></pre></td></tr></table></figure>
<ol start="4">
<li>解压到 /usr/bin</li>
</ol>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">unzip chromedriver_linux64.<span class="built_in">zip</span> /usr/<span class="built_in">bin</span></span><br></pre></td></tr></table></figure>
<ol start="5">
<li>查看chrome driver版本</li>
</ol>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line">chromedriver --version</span><br></pre></td></tr></table></figure>
<ol start="6">
<li>测试</li>
</ol>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">from</span> selenium <span class="keyword">import</span> webdriver</span><br><span class="line"> </span><br><span class="line">chrome_options = webdriver.ChromeOptions()</span><br><span class="line">chrome_options.add_argument(<span class="string">"--headless"</span>)</span><br><span class="line">chrome_options.add_argument(<span class="string">"--disable-gpu"</span>)</span><br><span class="line">chrome_options.add_argument(<span class="string">"--no-sandbox"</span>)</span><br><span class="line">browser = webdriver.Chrome(chrome_options=chrome_options)</span><br><span class="line">browser.get(<span class="string">"https://www.baidu.com"</span>)</span><br><span class="line"><span class="built_in">print</span>(browser.page_source)</span><br><span class="line">browser.quit()</span><br></pre></td></tr></table></figure>
<h2 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h2><p><a href="https://www.codeleading.com/article/73622389627/">linux云服务器使用selenium chrome chromedriver</a></p>
<p><a href="https://www.cnblogs.com/kimyeee/p/7250560.html">Linux下安装Python3.6和第三方库</a></p>
]]></content>
<tags>
<tag>selenium</tag>
<tag>Linux</tag>
<tag>chrome driver</tag>
</tags>
</entry>
</search>