-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspider-tianyancha.html
692 lines (633 loc) · 49.9 KB
/
spider-tianyancha.html
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
<!DOCTYPE html>
<html lang="zh-Hans"
>
<head>
<title>天眼查爬虫 - Tenghuiji's Blog</title>
<!-- Using the latest rendering mode for IE -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#6b5594">
<meta name="msapplication-navbutton-color" content="#6b5594">
<meta name="apple-mobile-web-app-status-bar-style" content="#6b5594">
<link rel="manifest" href="/manifest.json">
<link rel="apple-touch-icon" sizes="180x180" href="//tenghuiji.github.io/images/apple-touch-icon.png">
<link rel="icon" type="image/png" href="//tenghuiji.github.io/images/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="//tenghuiji.github.io/images/favicon-16x16.png" sizes="16x16">
<link rel="mask-icon" href="//tenghuiji.github.io/images/safari-pinned-tab.svg" color="#603cba">
<link rel="canonical" href="//tenghuiji.github.io/spider-tianyancha.html">
<meta name="author" content="tenghuiji" />
<meta name="keywords" content="python selenium BeautifulSoup xpath" />
<meta name="description" content="用 selenium 和 BeautifulSoup 爬取 www.tianyancha.com 的数据" />
<meta property="og:site_name" content="Tenghuiji's Blog" />
<meta property="og:type" content="article"/>
<meta property="og:title" content="天眼查爬虫"/>
<meta property="og:url" content="//tenghuiji.github.io/spider-tianyancha.html"/>
<meta property="og:description" content="用 selenium 和 BeautifulSoup 爬取 www.tianyancha.com 的数据"/>
<meta property="article:published_time" content="2018-03-26" />
<meta property="article:section" content="spider" />
<meta property="article:tag" content="python selenium BeautifulSoup xpath" />
<meta property="article:author" content="tenghuiji" />
<meta property="og:image"
content="//tenghuiji.github.io/spider-tianyancha.png"/>
<!-- Bootstrap -->
<link href="//tenghuiji.github.io/theme/css/bootstrap.min.css" rel="stylesheet">
<link href="//tenghuiji.github.io/theme/css/font-awesome.min.css" rel="stylesheet">
<link href="//tenghuiji.github.io/theme/css/pygments/monokai.css" rel="stylesheet">
<link href="//tenghuiji.github.io/theme/tipuesearch/tipuesearch.css" rel="stylesheet">
<link href="//tenghuiji.github.io/theme/css/html4css1.css" rel="stylesheet">
<link rel="stylesheet" href="//tenghuiji.github.io/theme/css/style.css" type="text/css"/>
<link href="//tenghuiji.github.io/feeds/atom.xml" type="application/atom+xml" rel="alternate"
title="Tenghuiji's Blog ATOM Feed"/>
<link href="//tenghuiji.github.io/theme/css/material.min.css" rel="stylesheet">
<link href="//tenghuiji.github.io/theme/css/ripples.css" rel="stylesheet">
<link href="//tenghuiji.github.io/theme/css/github-markdown.css" rel="stylesheet">
</head>
<body>
<div style="display:none" id="title">天眼查爬虫 - Tenghuiji's Blog</div>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only"> Toggle navigation
</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="//tenghuiji.github.io/" class="navbar-brand">
Tenghuiji's Blog </a>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li class="dropdown hidden-md hidden-lg hidden-xl">
<a class="dropdown-toggle" data-toggle="dropdown" href="javascript:void(0)">
<i class="fa fa-user"></i><span class="caret"></span>
</a>
<ul class="dropdown-menu">
</ul>
</li>
<ul class="nav navbar-nav hidden-xs hidden-sm">
</ul>
</ul>
<ul class="nav navbar-nav hidden-md hidden-lg hidden-xl">
<li class="dropdown hidden-md hidden-lg hidden-xl">
<a class="dropdown-toggle" data-toggle="dropdown" href="javascript:void(0)">
<i class="fa fa-folder-o"></i><span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li >
<a href="//tenghuiji.github.io/category/correlation-analysis.html"><i class="fa fa-folder-o"></i> Correlation analysis</a>
</li>
<li >
<a href="//tenghuiji.github.io/category/review.html"><i class="fa fa-folder-o"></i> Review</a>
</li>
<li class="active">
<a href="//tenghuiji.github.io/category/spider.html"><i class="fa fa-folder-o"></i> Spider</a>
</li>
<li >
<a href="//tenghuiji.github.io/category/vm.html"><i class="fa fa-folder-o"></i> Vm</a>
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav hidden-xs hidden-sm">
<li >
<a href="//tenghuiji.github.io/category/correlation-analysis.html"><i class="fa fa-folder-o"></i> Correlation analysis</a>
</li>
<li >
<a href="//tenghuiji.github.io/category/review.html"><i class="fa fa-folder-o"></i> Review</a>
</li>
<li class="active">
<a href="//tenghuiji.github.io/category/spider.html"><i class="fa fa-folder-o"></i> Spider</a>
</li>
<li >
<a href="//tenghuiji.github.io/category/vm.html"><i class="fa fa-folder-o"></i> Vm</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right hidden-sm hidden-md hidden-lg hidden-xl">
<li class="dropdown hidden-md hidden-lg hidden-xl">
<a class="dropdown-toggle" data-toggle="dropdown" href="javascript:void(0)">
<i class="fa fa-search"></i><span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><span>
<form class="navbar-search" action="/search.html">
<input type="text" class="search-query form-control col-lg-16" placeholder=" Search
" name="q" id="tipue_search_input" required>
</form></span>
</li>
</ul>
</li>
</ul>
<ul class="nav navbar-right navbar-form hidden-xs">
<li><span>
<form class="navbar-search" action="/search.html">
<input type="text" class="search-query form-control col-lg-16" placeholder=" Search
" name="q" id="tipue_search_input" required>
</form></span>
</li>
</ul>
<ul class="nav navbar-nav navbar-right hidden-xs">
<li><a href="//tenghuiji.github.io/archives.html"><i class="fa fa-th-list"></i><span class="icon-label"> All
</span></a></li>
<li><a href="//tenghuiji.github.io/feeds/atom.xml" title="Atom feeds for all articles"><i class="fa fa-rss"></i></a></li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
</div> <!-- /.navbar -->
<!-- Banner -->
<!-- End Banner -->
<div class="container" style="min-height: 100%;height: auto !important;height: 100%;">
<div class="row" style="padding-bottom:80px;padding-top:80px;">
<div class="col-xl-21 col-lg-20 col-md-18">
<div id="loading-block">
<ol class="breadcrumb">
<li><a href="//tenghuiji.github.io/" title="Tenghuiji's Blog"><i class="fa fa-home fa-lg"></i></a></li>
<li><a href="//tenghuiji.github.io/category/spider.html" title="spider">spider</a></li>
<li class="active">天眼查爬虫</li>
</ol>
<section id="content" class="article-content">
<article>
<header class="page-header jumbotron jumbotron-primary panel-primary" id="article-header">
<div class="panel-heading">
<h1>
天眼查爬虫
<a href="//tenghuiji.github.io/spider-tianyancha.html"
rel="bookmark"
class="btn btn-primary btn-lg"
title=" Permalink to 天眼查爬虫
">
<i class="mdi-action-launch"></i>
</a>
</h1>
</div>
<div class="panel-body">
<div class="post-info">
<span class="published">
<time datetime="2018-03-26T20:00:00+08:00"><i class="fa fa-calendar"></i> 2018年03月26日(周一)</time>
</span>
<a onclick="$.get('//tenghuiji.github.io/spider-tianyancha.rst.html', function(data){$('#source-code').html(data)});$('#article-content').toggle();$('#source-content').toggle();" class="btn btn-primary" title=" Show source code of this page
"><i class="fa fa-code"></i></a>
<!--<a href="//tenghuiji.github.io/spider-tianyancha.pdf" class="btn btn-primary" title=" Show pdf version of this page
" target="_blank"><i class="fa fa-file-pdf-o"></i></a>
<a href="//tenghuiji.github.io/spider-tianyancha.png" class="btn btn-primary" title=" Show captured png of this page
" target="_blank""><i class="fa fa-file-photo-o"></i></a>-->
<span class="btn-group">
<a href="//tenghuiji.github.io/tag/python-selenium-beautifulsoup-xpath.html" class="btn btn-primary btn-xs"><i class="fa fa-tag"></i> python selenium BeautifulSoup xpath</a>
</span>
</div><!-- /.post-info --> </div>
</header>
<div class="entry-content jumbotron" id="article-content">
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h1 id="天眼查爬虫">天眼查爬虫<a class="anchor-link" href="#天眼查爬虫">¶</a></h1><p>2018-1-21<br/>
marking的同事跑过来求帮忙,能不能通过爬虫帮他,根据会议收集表格中,人员名单所填写的公司名称添加一列行业信息。<br/>
他目前是手工到天眼输入公司名称,然后再取出觉得匹配的公司,最后在找到行业分类。但是人员明天太多了,做这么枯燥的工作他要疯了:(<br/>
我觉得这个应该比较简单,答应他帮他写个爬虫</p>
<h6 id="确定爬取方式">确定爬取方式<a class="anchor-link" href="#确定爬取方式">¶</a></h6><p>selenium是个自动化测试工具,他可以通过浏览器来模拟各种操作实现测试页面功能<br/>
BeautifulSoup是个爬虫常用的Dom解析工具<br/>
lxml提供了xpath获取方法,强烈推荐通过xpath访问节点,配合Chrome的inspect工具中的 copy xpath可以节省大量的节点获取工作量</p>
<h6 id="安装必要的工具">安装必要的工具<a class="anchor-link" href="#安装必要的工具">¶</a></h6><p>pip install selenium<br/>
pip install lxml<br/>
pip install beautifulsoup4<br/>
下载最新的chromedriver<br/>
<a href="http://chromedriver.storage.googleapis.com/index.html">http://chromedriver.storage.googleapis.com/index.html</a><br/>
我是mac 安装到/usr/local/bin/目录下,然后运行 chromedriver -v查看是否安装好了</p>
<h6 id="常见问题">常见问题<a class="anchor-link" href="#常见问题">¶</a></h6><ol>
<li>公司名称不存在;在天眼搜里面找不到公司名称就在程序中填写none或者其他的字符说明 </li>
<li>相似公司很多个不确定怎么选;这个比较不好处理,现在是取天眼搜中查找到的top 1 记录 我想人选择的话可能会根据与会者所在地配合来查找吧,例如是在北京参加的,那么就有限找北京的同名(名称相似)的公司 </li>
<li>天眼里面找到的母公司下面有多个子公司,导致鼠标点击不到连接,必须拉滚动条才能解决问题 </li>
</ol>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [30]:</div>
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span class="code-line"><span></span><span class="kn">from</span> <span class="nn">selenium</span> <span class="k">import</span> <span class="n">webdriver</span></span>
<span class="code-line"><span class="kn">from</span> <span class="nn">selenium.common.exceptions</span> <span class="k">import</span> <span class="n">TimeoutException</span></span>
<span class="code-line"><span class="kn">from</span> <span class="nn">selenium.webdriver.common.by</span> <span class="k">import</span> <span class="n">By</span></span>
<span class="code-line"><span class="kn">from</span> <span class="nn">selenium.webdriver.support.ui</span> <span class="k">import</span> <span class="n">WebDriverWait</span></span>
<span class="code-line"><span class="kn">from</span> <span class="nn">selenium.webdriver.support</span> <span class="k">import</span> <span class="n">expected_conditions</span> <span class="k">as</span> <span class="n">EC</span></span>
<span class="code-line"><span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span></span>
<span class="code-line"><span class="kn">from</span> <span class="nn">bs4</span> <span class="k">import</span> <span class="n">BeautifulSoup</span></span>
<span class="code-line"><span class="kn">from</span> <span class="nn">lxml</span> <span class="k">import</span> <span class="n">etree</span></span>
<span class="code-line"><span class="kn">import</span> <span class="nn">time</span></span>
<span class="code-line"><span class="kn">import</span> <span class="nn">random</span></span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [31]:</div>
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span class="code-line"><span></span><span class="k">def</span> <span class="nf">search</span><span class="p">(</span><span class="n">keywords</span><span class="p">):</span></span>
<span class="code-line"> <span class="c1"># print('正在搜索:{}'.format(keywords))</span></span>
<span class="code-line"> <span class="k">try</span><span class="p">:</span></span>
<span class="code-line"> <span class="n">browser</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">'https://www.tianyancha.com/'</span><span class="p">)</span></span>
<span class="code-line"> <span class="c1"># 找到输入框</span></span>
<span class="code-line"> <span class="nb">input</span> <span class="o">=</span> <span class="n">wait</span><span class="o">.</span><span class="n">until</span><span class="p">(</span></span>
<span class="code-line"> <span class="n">EC</span><span class="o">.</span><span class="n">presence_of_element_located</span><span class="p">(</span></span>
<span class="code-line"> <span class="p">(</span><span class="n">By</span><span class="o">.</span><span class="n">CSS_SELECTOR</span><span class="p">,</span></span>
<span class="code-line"> <span class="s1">'.main-tab-outer .main-tab-body .inputV2 input'</span><span class="p">)))</span></span>
<span class="code-line"> <span class="c1"># input.send_keys(keywords.decode('utf-8'))#中英混输入可防止乱码</span></span>
<span class="code-line"> <span class="nb">input</span><span class="o">.</span><span class="n">send_keys</span><span class="p">(</span><span class="n">keywords</span><span class="p">)</span></span>
<span class="code-line"> <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">sample</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">],</span> <span class="mi">1</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span></span>
<span class="code-line"> <span class="n">submit</span> <span class="o">=</span> <span class="n">wait</span><span class="o">.</span><span class="n">until</span><span class="p">(</span></span>
<span class="code-line"> <span class="n">EC</span><span class="o">.</span><span class="n">element_to_be_clickable</span><span class="p">(</span></span>
<span class="code-line"> <span class="p">(</span><span class="n">By</span><span class="o">.</span><span class="n">CSS_SELECTOR</span><span class="p">,</span></span>
<span class="code-line"> <span class="s1">'.mainv2_tab1 .inputV2 .search_button.white-btn'</span><span class="p">)))</span></span>
<span class="code-line"> <span class="n">submit</span><span class="o">.</span><span class="n">click</span><span class="p">()</span></span>
<span class="code-line"></span>
<span class="code-line"> <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">sample</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">],</span> <span class="mi">1</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span></span>
<span class="code-line"></span>
<span class="code-line"> <span class="c1"># 获取打开的多个窗口句柄</span></span>
<span class="code-line"> <span class="n">windows</span> <span class="o">=</span> <span class="n">browser</span><span class="o">.</span><span class="n">window_handles</span></span>
<span class="code-line"> <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">sample</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">],</span> <span class="mi">1</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span></span>
<span class="code-line"> <span class="c1"># 切换到当前最新打开的窗口</span></span>
<span class="code-line"> <span class="n">browser</span><span class="o">.</span><span class="n">switch_to</span><span class="o">.</span><span class="n">window</span><span class="p">(</span><span class="n">windows</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span></span>
<span class="code-line"> <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">sample</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">],</span> <span class="mi">1</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span></span>
<span class="code-line"></span>
<span class="code-line"> <span class="c1"># 用目标元素参考去拖动</span></span>
<span class="code-line"> <span class="n">target_elem</span> <span class="o">=</span> <span class="n">browser</span><span class="o">.</span><span class="n">find_element_by_xpath</span><span class="p">(</span></span>
<span class="code-line"> <span class="s1">'//*[@id="web-content"]/div/div/div/div[1]/div[3]/div[1]/div[1]'</span><span class="p">)</span></span>
<span class="code-line"> <span class="n">js</span> <span class="o">=</span> <span class="s1">'arguments[0].scrollIntoView();'</span></span>
<span class="code-line"> <span class="n">browser</span><span class="o">.</span><span class="n">execute_script</span><span class="p">(</span><span class="n">js</span><span class="p">,</span> <span class="n">target_elem</span><span class="p">)</span></span>
<span class="code-line"></span>
<span class="code-line"> <span class="c1"># 在搜索结果中获取第一个公司</span></span>
<span class="code-line"> <span class="n">top1</span> <span class="o">=</span> <span class="n">wait</span><span class="o">.</span><span class="n">until</span><span class="p">(</span></span>
<span class="code-line"> <span class="n">EC</span><span class="o">.</span><span class="n">element_to_be_clickable</span><span class="p">((</span><span class="n">By</span><span class="o">.</span><span class="n">CSS_SELECTOR</span><span class="p">,</span></span>
<span class="code-line"> <span class="s1">'.search_result_container a'</span><span class="p">)))</span></span>
<span class="code-line"> <span class="n">top1</span><span class="o">.</span><span class="n">click</span><span class="p">()</span></span>
<span class="code-line"></span>
<span class="code-line"> <span class="c1"># 关闭当前窗口</span></span>
<span class="code-line"> <span class="n">browser</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></span>
<span class="code-line"></span>
<span class="code-line"> <span class="c1"># 获取打开的多个窗口句柄</span></span>
<span class="code-line"> <span class="n">windows</span> <span class="o">=</span> <span class="n">browser</span><span class="o">.</span><span class="n">window_handles</span></span>
<span class="code-line"> <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">sample</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">],</span> <span class="mi">1</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span></span>
<span class="code-line"> <span class="c1"># 切换到当前最新打开的窗口</span></span>
<span class="code-line"> <span class="n">browser</span><span class="o">.</span><span class="n">switch_to</span><span class="o">.</span><span class="n">window</span><span class="p">(</span><span class="n">windows</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span></span>
<span class="code-line"> <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">sample</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">],</span> <span class="mi">1</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span></span>
<span class="code-line"></span>
<span class="code-line"> <span class="c1"># 等待页面全部加载完成</span></span>
<span class="code-line"> <span class="n">wait</span><span class="o">.</span><span class="n">until</span><span class="p">(</span></span>
<span class="code-line"> <span class="n">EC</span><span class="o">.</span><span class="n">presence_of_all_elements_located</span><span class="p">((</span><span class="n">By</span><span class="o">.</span><span class="n">CSS_SELECTOR</span><span class="p">,</span></span>
<span class="code-line"> <span class="s1">'#_container_baseInfo'</span><span class="p">)))</span></span>
<span class="code-line"> <span class="n">selector</span> <span class="o">=</span> <span class="n">etree</span><span class="o">.</span><span class="n">HTML</span><span class="p">(</span><span class="n">browser</span><span class="o">.</span><span class="n">page_source</span><span class="p">)</span></span>
<span class="code-line"></span>
<span class="code-line"> <span class="c1"># 获取公司名称</span></span>
<span class="code-line"> <span class="n">company_name</span> <span class="o">=</span> <span class="n">selector</span><span class="o">.</span><span class="n">xpath</span><span class="p">(</span></span>
<span class="code-line"> <span class="s1">'//*[@id="company_web_top"]/div[2]/div[2]/div[1]/span/text()'</span><span class="p">)</span></span>
<span class="code-line"> <span class="c1"># 获取公司信息表格中的行业信息xpath //*[@id="_container_baseInfo"]/div/div[3]/table/tbody/tr[3]/td[4]/text()</span></span>
<span class="code-line"> <span class="n">links</span> <span class="o">=</span> <span class="n">selector</span><span class="o">.</span><span class="n">xpath</span><span class="p">(</span></span>
<span class="code-line"> <span class="s1">'//*[@id="_container_baseInfo"]/div/div[3]/table/tbody/tr[3]/td[4]/text()'</span></span>
<span class="code-line"> <span class="p">)</span></span>
<span class="code-line"> <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="n">random</span><span class="o">.</span><span class="n">sample</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">],</span> <span class="mi">1</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span></span>
<span class="code-line"> <span class="k">for</span> <span class="n">link</span> <span class="ow">in</span> <span class="n">links</span><span class="p">:</span></span>
<span class="code-line"> <span class="n">s</span> <span class="o">=</span><span class="s1">'公司名称:</span><span class="si">{}</span><span class="s1">,找到的公司:</span><span class="si">{}</span><span class="s1">,所属行业:</span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">keywords</span><span class="p">,</span> <span class="n">company_name</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span></span>
<span class="code-line"> <span class="n">link</span><span class="p">)</span></span>
<span class="code-line"> <span class="nb">print</span><span class="p">(</span><span class="n">s</span><span class="p">)</span></span>
<span class="code-line"> <span class="k">return</span> <span class="n">s</span></span>
<span class="code-line"> <span class="c1"># browser.close()</span></span>
<span class="code-line"> <span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span></span>
<span class="code-line"> <span class="n">s</span> <span class="o">=</span><span class="s1">'公司名称:</span><span class="si">{}</span><span class="s1">,找到的公司:</span><span class="si">{}</span><span class="s1">,所属行业:</span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">keywords</span><span class="p">,</span> <span class="s1">'NaN'</span><span class="p">,</span> <span class="s1">'NaN'</span><span class="p">)</span></span>
<span class="code-line"> <span class="nb">print</span><span class="p">(</span><span class="s1">'公司名称:</span><span class="si">{}</span><span class="s1">,找到的公司:</span><span class="si">{}</span><span class="s1">,所属行业:</span><span class="si">{}</span><span class="s1">'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">keywords</span><span class="p">,</span> <span class="s1">'NaN'</span><span class="p">,</span> <span class="s1">'NaN'</span><span class="p">))</span></span>
<span class="code-line"> <span class="k">return</span> <span class="n">s</span></span>
<span class="code-line"> <span class="c1">#pass</span></span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [36]:</div>
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span class="code-line"><span></span><span class="c1">#跟新数据</span></span>
<span class="code-line"><span class="k">def</span> <span class="nf">updateString</span><span class="p">(</span><span class="n">ss</span><span class="p">):</span></span>
<span class="code-line"> <span class="k">return</span> <span class="n">ss</span><span class="p">[</span><span class="n">ss</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">','</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">:]</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="c1">#提取查找输入的公司名称</span></span>
<span class="code-line"><span class="k">def</span> <span class="nf">splitCompanyNameColumn</span><span class="p">(</span><span class="n">ss</span><span class="p">):</span></span>
<span class="code-line"> <span class="nb">print</span><span class="p">(</span><span class="n">ss</span><span class="p">)</span></span>
<span class="code-line"> <span class="k">return</span> <span class="n">ss</span><span class="p">[</span><span class="n">ss</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">':'</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">:</span><span class="n">ss</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">','</span><span class="p">)]</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="c1">#提取找到的公司名称</span></span>
<span class="code-line"><span class="k">def</span> <span class="nf">splitFindCompanyNameColumn</span><span class="p">(</span><span class="n">ss</span><span class="p">):</span></span>
<span class="code-line"> <span class="nb">print</span><span class="p">(</span><span class="n">ss</span><span class="p">)</span></span>
<span class="code-line"> <span class="k">return</span> <span class="n">ss</span><span class="p">[</span><span class="n">ss</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">':'</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">:</span><span class="n">ss</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">','</span><span class="p">)]</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="c1">#提取找到的所属行业</span></span>
<span class="code-line"><span class="k">def</span> <span class="nf">splitIndustryColumn</span><span class="p">(</span><span class="n">ss</span><span class="p">):</span></span>
<span class="code-line"> <span class="nb">print</span><span class="p">(</span><span class="n">ss</span><span class="p">)</span></span>
<span class="code-line"> <span class="k">return</span> <span class="n">ss</span><span class="p">[</span><span class="n">ss</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">':'</span><span class="p">)</span><span class="o">+</span><span class="mi">1</span><span class="p">:</span><span class="n">ss</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s1">','</span><span class="p">)]</span></span>
</pre></div>
</div>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [39]:</div>
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span class="code-line"><span></span><span class="c1"># 启动浏览器,executable_path路径要根据自己chromedriver.exe的位置更改</span></span>
<span class="code-line"><span class="n">browser</span> <span class="o">=</span> <span class="n">webdriver</span><span class="o">.</span><span class="n">Chrome</span><span class="p">(</span><span class="n">executable_path</span><span class="o">=</span><span class="sa">r</span><span class="s1">'/usr/local/bin/chromedriver'</span><span class="p">)</span></span>
<span class="code-line"><span class="c1"># 设置浏览器窗口位置及大小</span></span>
<span class="code-line"><span class="n">browser</span><span class="o">.</span><span class="n">set_window_rect</span><span class="p">(</span><span class="n">x</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">1200</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="mi">750</span><span class="p">)</span></span>
<span class="code-line"><span class="c1"># 设定页面加载限制时间</span></span>
<span class="code-line"><span class="n">browser</span><span class="o">.</span><span class="n">set_page_load_timeout</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span></span>
<span class="code-line"><span class="c1"># 设置锁定标签等待时长</span></span>
<span class="code-line"><span class="n">wait</span> <span class="o">=</span> <span class="n">WebDriverWait</span><span class="p">(</span><span class="n">browser</span><span class="p">,</span> <span class="mi">20</span><span class="p">)</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">read_csv</span><span class="p">(</span><span class="s1">'./dataset/Jam_data_analysis.csv'</span><span class="p">)</span></span>
<span class="code-line"><span class="n">df</span><span class="p">[</span><span class="s1">'临时'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">'公司'</span><span class="p">]</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">search</span><span class="p">)</span></span>
<span class="code-line"><span class="n">df</span><span class="p">[</span><span class="s1">'公司名称'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">'临时'</span><span class="p">]</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">splitCompanyNameColumn</span><span class="p">)</span></span>
<span class="code-line"><span class="n">df</span><span class="p">[</span><span class="s1">'临时'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">'临时'</span><span class="p">]</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">updateString</span><span class="p">)</span></span>
<span class="code-line"><span class="n">df</span><span class="p">[</span><span class="s1">'找到的公司'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">'临时'</span><span class="p">]</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">splitFindCompanyNameColumn</span><span class="p">)</span></span>
<span class="code-line"><span class="n">df</span><span class="p">[</span><span class="s1">'临时'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">'临时'</span><span class="p">]</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">updateString</span><span class="p">)</span></span>
<span class="code-line"><span class="n">df</span><span class="p">[</span><span class="s1">'所属行业'</span><span class="p">]</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="s1">'临时'</span><span class="p">]</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="n">splitIndustryColumn</span><span class="p">)</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="c1">#删除临时字段</span></span>
<span class="code-line"><span class="k">del</span> <span class="n">df</span><span class="p">[</span><span class="s1">'临时'</span><span class="p">]</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="c1">#关闭浏览器</span></span>
<span class="code-line"><span class="n">browser</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></span>
<span class="code-line"></span>
<span class="code-line"><span class="c1">#保存结果到csv文件中</span></span>
<span class="code-line"><span class="n">df</span><span class="o">.</span><span class="n">to_csv</span><span class="p">(</span><span class="s1">'./dataset/output.csv'</span><span class="p">)</span></span>
</pre></div>
</div>
</div>
</div>
<div class="output_wrapper">
<div class="output">
<div class="output_area">
<div class="prompt"></div>
<div class="output_subarea output_stream output_stdout output_text">
<pre><span class="code-line">公司名称:小米,找到的公司:小米科技有限责任公司,所属行业:科技推广和应用服务业</span>
<span class="code-line">公司名称:猎豹汽车研究院,找到的公司:NaN,所属行业:NaN</span>
<span class="code-line">公司名称:滴滴出行,找到的公司:NaN,所属行业:NaN</span>
<span class="code-line">0 公司名称:小米,找到的公司:小米科技有限责任公司,所属行业:科技推广和应用服务业</span>
<span class="code-line">1 公司名称:猎豹汽车研究院,找到的公司:NaN,所属行业:NaN</span>
<span class="code-line">2 公司名称:滴滴出行,找到的公司:NaN,所属行业:NaN</span>
<span class="code-line">Name: 临时, dtype: object</span>
<span class="code-line">公司名称:小米,找到的公司:小米科技有限责任公司,所属行业:科技推广和应用服务业</span>
<span class="code-line">公司名称:猎豹汽车研究院,找到的公司:NaN,所属行业:NaN</span>
<span class="code-line">公司名称:滴滴出行,找到的公司:NaN,所属行业:NaN</span>
<span class="code-line">0 找到的公司:小米科技有限责任公司,所属行业:科技推广和应用服务业</span>
<span class="code-line">1 找到的公司:NaN,所属行业:NaN</span>
<span class="code-line">2 找到的公司:NaN,所属行业:NaN</span>
<span class="code-line">Name: 临时, dtype: object</span>
<span class="code-line">找到的公司:小米科技有限责任公司,所属行业:科技推广和应用服务业</span>
<span class="code-line">找到的公司:NaN,所属行业:NaN</span>
<span class="code-line">找到的公司:NaN,所属行业:NaN</span>
<span class="code-line">0 所属行业:科技推广和应用服务业</span>
<span class="code-line">1 所属行业:NaN</span>
<span class="code-line">2 所属行业:NaN</span>
<span class="code-line">Name: 临时, dtype: object</span>
<span class="code-line">所属行业:科技推广和应用服务业</span>
<span class="code-line">所属行业:NaN</span>
<span class="code-line">所属行业:NaN</span>
</pre>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">if (!document.getElementById('mathjaxscript_pelican_#%@#$@#')) {
var mathjaxscript = document.createElement('script');
mathjaxscript.id = 'mathjaxscript_pelican_#%@#$@#';
mathjaxscript.type = 'text/javascript';
mathjaxscript.src = '//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML';
mathjaxscript[(window.opera ? "innerHTML" : "text")] =
"MathJax.Hub.Config({" +
" config: ['MMLorHTML.js']," +
" TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'AMS' } }," +
" jax: ['input/TeX','input/MathML','output/HTML-CSS']," +
" extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," +
" displayAlign: 'center'," +
" displayIndent: '0em'," +
" showMathMenu: true," +
" tex2jax: { " +
" inlineMath: [ ['$','$'] ], " +
" displayMath: [ ['$$','$$'] ]," +
" processEscapes: true," +
" preview: 'TeX'," +
" }, " +
" 'HTML-CSS': { " +
" linebreaks: { automatic: true, width: '95% container' }, " +
" styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'black ! important'} }" +
" } " +
"}); ";
(document.body || document.getElementsByTagName('head')[0]).appendChild(mathjaxscript);
}
</script>
</div>
<div class="entry-content jumbotron" id="source-content" style="display: none">
<!-- <pre><code id="source-code">
</code></pre> -->
<div id="source-code"></div>
</div>
<!-- /.entry-content -->
<div class="row" id="prevnext">
<div class="col-xs-12">
<a href="//tenghuiji.github.io/Correlation_Analysis.html" class="btn btn-default btn-lg" style="float:left;clear:both;background-color:#fff;">
<h4><i class="fa fa-arrow-left"></i>
北京 PM2.5 相关性分析
</h4>
</a>
</div>
<div class="col-xs-12">
<a href="//tenghuiji.github.io/VM Ware EXSI.html" class="btn btn-default btn-lg" style="float:right;clear:both;background-color:#fff;">
<h4>
VM_Ware_EXSI创建虚拟机<i class="fa fa-arrow-right"></i>
</h4>
</a>
</div>
</div>
<section class="comments" id="comments">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
</div>
</section> </article>
</section>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<a data-dismiss="modal" href="javascript:void(0);">
<img id="mimg" src="" style="width:100%;height:auto">
</a>
</div>
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
</div>
<div class="col-xl-3 col-lg-4 col-md-6" id="sidebar">
<aside>
<section>
<div class="sidebar-container">
<div class="sidebar-item ">
<div class="panel panel-default">
<div class="panel-heading">
<h4>
<i class="fa fa-user fa-lg"></i>
<a href="//tenghuiji.github.io/about.html">
About Tenghuiji
</a>
</h4>
</div>
<div class="panel-body" id="aboutme">
<a href="//tenghuiji.github.io/about.html"><img width="100%" src="//tenghuiji.github.io/../images/avatar.jpg"/></a>
<h3 style="text-align:center">
<a href="https://github.com/tenghuiji" target="_blank">
<i class="fa fa-github" style="text-align:center"></i></a>
<a href="https://twitter.com/tenghuiji" target="_blank">
<i class="fa fa-twitter" style="text-align:center"></i></a>
<a href="http://weibo.com/thjgo" target="_blank">
<i class="fa fa-weibo" style="text-align:center"></i></a>
<a href="mailto:[email protected]" target="_blank">
<i class="mdi-communication-email" style="text-align:center"></i></a>
</h3>
</div>
</div>
</div>
<div class="sidebar-item hidden-xs">
<div class="panel panel-default">
<div class="panel-heading">
<h4>
<a href="//tenghuiji.github.io/tags.html"><i class="fa fa-tags fa-lg"></i><span class="icon-label"> Tags
</span></a>
</h4>
</div>
<div class="panel-body">
<ul class="list-group list-inline tagcloud" id="tags">
<li class="list-group-item tag-4">
<a href="//tenghuiji.github.io/tag/vm-exsi.html">
VM EXSI <sup> 1</sup>
</a>
</li>
<li class="list-group-item tag-4">
<a href="//tenghuiji.github.io/tag/python-selenium-beautifulsoup-xpath.html">
python selenium BeautifulSoup xpath <sup> 1</sup>
</a>
</li>
<li class="list-group-item tag-4">
<a href="//tenghuiji.github.io/tag/python-correlation-analysis.html">
python Correlation Analysis <sup> 1</sup>
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="sidebar-item hidden-xs">
<div class="panel panel-default">
<div class="panel-heading">
<h4>
<i class="fa fa-github fa-lg"></i><span class="icon-label"> GitHub Repos
</span>
</h4>
</div>
<div class="panel-body">
<div id="gh_repos">
<p class="list-group-item">Status updating...</p>
</div>
<a href="https://github.com/tenghuiji">@tenghuiji</a> on GitHub<br>
</div>
</div>
</div>
</div>
</section>
</aside>
</div>
</div>
</div>
<footer id="fcfooter">
<hr/>
<div class="container">
<div class="row">
<div class="col-md-24">
<p><small>
© 2018 Tenghuiji
· Powered by
<a href="http://docs.getpelican.com/" target="_blank">Pelican</a> generator
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="//i.creativecommons.org/l/by-nc-sa/4.0/80x15.png" /></a>
<!-- Content -->
<!-- licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution 4.0 International License</a>, except where indicated otherwise. -->
</small></p>
</div>
</div>
</div>
<a href="#" class="btn btn-primary btn-fab btn-raised mdi-editor-vertical-align-top withripple" style="position:fixed;bottom:30px;right:30px;z-index:1000"></a>
</footer>
<script src="//tenghuiji.github.io/theme/js/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="//tenghuiji.github.io/theme/js/bootstrap.min.js"></script>
<!-- Enable responsive features in IE8 with Respond.js (https://github.com/scottjehl/Respond) -->
<script src="//tenghuiji.github.io/theme/js/respond.min.js"></script>
<!-- GitHub JS -->
<script type="text/javascript">
$(document).ready(function () {
if (!window.jXHR) {
var jxhr = document.createElement('script');
jxhr.type = 'text/javascript';
jxhr.src = '//tenghuiji.github.io/theme/js/jXHR.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(jxhr, s);
}
github.showRepos({
user: 'tenghuiji',
count: 5,
skip_forks: false,
target: '#gh_repos'
});
});
</script>
<script src="//tenghuiji.github.io/theme/js/github.js" type="text/javascript"></script>
<!-- End GitHub JS Code -->
<script src="//tenghuiji.github.io/theme/js/ripples.min.js"></script>
<script src="//tenghuiji.github.io/theme/js/material.min.js"></script>
<script src="//tenghuiji.github.io/theme/js/jquery.bootstrap-autohidingnavbar.min.js"></script>
<script>
$(document).ready(function() {
$.material.init();
$("div.navbar").autoHidingNavbar();
$(".img-responsive").css("cursor","pointer").on('click',function(){
var sr=$(this).attr('src');
$('#mimg').attr('src',sr);
$('#myModal').modal('show');
});
$('#affix-toc').affix({
offset: {
top: function(){
if($('#affix-toc').hasClass("affix"))
return $('#sidebar').height();
return $('#sidebar').height() - $('#affix-toc').height();
},
bottom: function (){
return $("#fcfooter").offset().top -
$("#article-content").offset().top -
$("#article-content").height() + 20;
}
}
});
$('#affix-toc').width($('#sidebar').width());
});
$(window).resize(function () {
$('#affix-toc').width($('#sidebar').width());
});
</script>
</body>
</html>