-
Notifications
You must be signed in to change notification settings - Fork 68
/
caiji.py
1319 lines (1277 loc) · 68.6 KB
/
caiji.py
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
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding:utf-8 -*-
import os
import re
import sys
import time
import json
import base64
import datetime
import requests
from lxml import etree
from threading import Thread
#单线程,多线程采集方式选择(多线程采集速度快但机器负载短时高)
thread = 'multi'
#thread = 'single'
#理论python和前端js会自动转义,但如果采集名称因引号或其它需转义的字符报错,请将相应采集名修改如下
#hot_name = .replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").replace("\"", "").replace("\'", "").strip()
#采集数据保存目录,为了安全请修改本程序名字,或移动到其他目录,并修改以下路径,默认与程序同目录
dir = os.path.dirname(os.path.abspath(__file__)) + "/json/"
#dir = "webrootdir/json/"
#dir = "/tmp/json/"
try:
os.mkdir(dir)
except:
print("json文件夹创建失败(已存在或无写入权限)")
#字符替换加密(默认为大小写反转),修改此处顺序和添加数字替换可实现不同密码加密(并同时修改get/index.php内密码)
def multiple_replace(text):
dic = {"a":"A", "b":"B", "c":"C", "d":"D", "e":"E", "f":"F", "g":"G", "h":"H", "i":"I", "j":"J", "k":"K", "l":"L", "m":"M", "n":"N", "o":"O", "p":"P", "q":"Q", "r":"R", "s":"S", "t":"T", "u":"U", "v":"V", "w":"W", "x":"X", "y":"Y", "z":"Z", "A":"a", "B":"b", "C":"c", "D":"d", "E":"e", "F":"f", "G":"g", "H":"h", "I":"i", "J":"j", "K":"k", "L":"l", "M":"m", "N":"n", "O":"o", "P":"p", "Q":"q", "R":"r", "S":"s", "T":"t", "U":"u", "V":"v", "W":"w", "X":"x", "Y":"y", "Z":"z"}
pattern = "|".join(map(re.escape, list(dic.keys())))
return re.sub(pattern, lambda m: dic[m.group()], text)
#UTC时间转本地时间(+8:00)
def utc2local(utc_st):
now_stamp = time.time()
local_time = datetime.datetime.fromtimestamp(now_stamp)
utc_time = datetime.datetime.utcfromtimestamp(now_stamp)
offset = local_time - utc_time
local_st = utc_st + offset
return local_st
def parse_baidu(name):
try:
jsondict= {}
if name == 'now':
jsondict["title"] = "百度实时热点"
url = "http://top.baidu.com/buzz?b=1"
if name == 'today':
jsondict["title"] = "百度今日热点"
url = "http://top.baidu.com/buzz?b=341"
if name == 'week':
jsondict["title"] = "百度七日热点"
url = "http://top.baidu.com/buzz?b=42"
fname = dir + "baidu_" + name + ".json"
r = requests.get(url, timeout=(5, 10))
r.encoding='gb2312'
soup = etree.HTML(r.text.replace("<tr >", "<tr class=\"hideline\">"))
list = []
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
for soup_a in soup.xpath("//tr[@class='hideline']"):
blist = {}
hot_name = soup_a.xpath("./td[2]/a[1]/text()")[0].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = soup_a.xpath("./td[2]/a[1]/@href")[0]
hot_num = soup_a.xpath("./td[@class='last']/span/text()")[0]
group = name
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
blist["num"]=hot_num
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"("+name+")"+"采集错误,请及时更新规则!")
#知乎热榜
def parse_zhihu_hot():
try:
fname = dir + "zhihu_hot.json"
zhihu_all = "https://www.zhihu.com/api/v3/feed/topstory/hot-lists/total?limit=50&desktop=true"
headers = {
'X-Requested-With': 'XMLHttpRequest',
'Referer': 'http://www.zhihu.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'Host': 'www.zhihu.com'
}
r = requests.get(zhihu_all, headers=headers, timeout=(5, 10)).text
data = json.loads(r)
news = data['data']
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "知乎全站热榜"
for n in news:
blist = {}
hot_name = n['target']['title'].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = n['target']['url'].replace("api.zhihu.com/questions/", "www.zhihu.com/question/")
group = "zhihu_hot"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#微博热点排行榜
def parse_weibo():
try:
fname = dir + "weibo.json"
weibo_ssrd = "https://s.weibo.com/top/summary?cate=realtimehot"
weibo = "https://s.weibo.com"
r = requests.get(weibo_ssrd, timeout=(5, 10))
r.encoding='utf-8'
soup = etree.HTML(r.text)
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "微博热点排行榜"
for soup_a in soup.xpath("//td[@class='td-02']"):
blist = {}
hot_name = soup_a.xpath("./a/text()")[0].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = weibo + soup_a.xpath("./a/@href")[0]
try:
hot_num = soup_a.xpath("./span/text()")[0]
except IndexError:
hot_num = ''
# hot_num = None #与''皆是赋值空
if "javascript:void(0)" in hot_url: #过滤微博的广告,做个判断
str_list = ""
else:
group = "weibo"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
if hot_num:
blist["num"]=hot_num
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#贴吧热度榜单
def parse_tieba():
try:
fname = dir + "tieba.json"
tb_url = "http://tieba.baidu.com/hottopic/browse/topicList"
headers = {
'X-Requested-With': 'XMLHttpRequest',
'Referer': 'http://tieba.baidu.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'Host': 'tieba.baidu.com'
}
r = requests.get(tb_url, headers=headers, timeout=(5, 10)).text
data = json.loads(r)
news = data['data']['bang_topic']['topic_list']
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "贴吧热度榜单"
for n in news:
blist = {}
hot_name = n['topic_desc'].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = n['topic_url'].replace("&", "&")
group = "tieba"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#V2EX热帖
def parse_v2ex():
try:
url = "https://www.v2ex.com/?tab=hot"
fname = dir + "v2ex.json"
r = requests.get(url, timeout=(5, 10))
soup = etree.HTML(r.text)
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "V2EX热帖"
for soup_a in soup.xpath("//span[@class='item_title']/a"):
blist = {}
hot_name = soup_a.text.replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = "https://www.v2ex.com" + soup_a.get('href')
group = "v2ex"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#豆瓣讨论精选
def parse_douban():
try:
url = "https://www.douban.com/group/explore"
headers = {
'Host': 'www.douban.com',
'Referer': 'https://www.douban.com/group/explore'
}
fname = dir + "douban.json"
r = requests.get(url, headers=headers, timeout=(5, 10))
soup = etree.HTML(r.text)
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "豆瓣讨论精选"
for soup_a in soup.xpath("//div[@class='channel-item']/div[@class='bd']/h3/a"):
blist = {}
hot_name = soup_a.text.replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = soup_a.get('href')
group = "douban"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#天涯热帖
def parse_tianya():
try:
url = "http://bbs.tianya.cn/hotArticle.jsp"
headers = {
'Host': 'bbs.tianya.cn',
'Referer': 'http://bbs.tianya.cn/hotArticle.jsp'
}
fname = dir + "tianya.json"
r = requests.get(url, headers=headers, timeout=(5, 10))
soup = etree.HTML(r.text)
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "天涯热帖"
for soup_a in soup.xpath("//div[@class='mt5']/table/tbody/tr/td[@class='td-title']/a"):
blist = {}
hot_name = soup_a.text.replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = 'http://bbs.tianya.cn' + soup_a.get('href')
group = "tianya"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#抽屉新热榜
def parse_chouti():
try:
url = "https://dig.chouti.com/link/hot"
headers = {
'Referer': 'https://dig.chouti.com/',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
}
fname = dir + "chouti.json"
r = requests.get(url, headers=headers, timeout=(5, 10)).text
data = json.loads(r)
news = data['data']
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(str(data['data'][0]['time_into_pool'])[0:10])))
jsondict["time"] = list_time
jsondict["title"] = "抽屉新热榜"
for n in news:
blist = {}
hot_url = n['originalUrl']
if 'chouti.com' not in hot_url:
hot_name = n['title'].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
group = "chouti"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#虎嗅网资讯
def parse_huxiu():
try:
url = "https://www-api.huxiu.com/v1/article/list"
headers = {
'Referer': 'https://www.huxiu.com/article',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
}
fname = dir + "huxiu.json"
r = requests.get(url, headers=headers, timeout=(5, 10)).text
data = json.loads(r)
news = data['data']['dataList']
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(data['data']['dataList'][0]['dateline'])))
jsondict["time"] = list_time
jsondict["title"] = "虎嗅网资讯"
for n in news:
blist = {}
hot_url = n['share_url']
hot_name = n['title'].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
group = "huxiu"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#煎蛋网
def parse_jandan():
try:
url = "https://jandan.net/"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'Referer': 'https://jandan.net/'
}
fname = dir + "jandan.json"
r = requests.get(url, headers=headers, timeout=(5, 10))
soup = etree.HTML(r.text)
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "煎蛋网"
for soup_a in soup.xpath("//div[@class='post f list-post']/div[@class='indexs']/h2/a"):
blist = {}
hot_name = soup_a.text.replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = soup_a.get('href')
group = "jandan"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#知乎日报
def parse_zhihu_daily():
try:
url = "https://daily.zhihu.com/"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'Referer': 'https://daily.zhihu.com/'
}
fname = dir + "zhihu_daily.json"
r = requests.get(url, headers=headers, timeout=(5, 10)).text.replace(" class=\"home\"", "")
soup = etree.HTML(r)
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "知乎日报"
for soup_a in soup.xpath("//div[@class='box']/a"):
blist = {}
hot_name = soup_a.xpath('./span/text()')[0].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = "https://daily.zhihu.com" + soup_a.get('href')
group = "zhihu_daily"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#黑客派-好玩
def parse_hacpai(name):
try:
jsondict= {}
if name=="play":
jsondict["title"] = "黑客派-好玩"
group = "hacpai_play"
url = "https://hacpai.com/domain/play"
if name=="hot":
jsondict["title"] = "黑客派-热议"
group = "hacpai_hot"
url = "https://hacpai.com/recent/hot"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'Referer': 'https://hacpai.com/'
}
fname = dir + "hacpai_"+name+".json"
r = requests.get(url, headers=headers, timeout=(5, 10))
soup = etree.HTML(r.text)
list = []
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
for soup_a in soup.xpath("//h2[@class='article-list__title article-list__title--view fn__flex-1']/a[@data-id]"):
blist = {}
hot_name = soup_a.text.replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = soup_a.get('href')
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"("+name+")"+"采集错误,请及时更新规则!")
#猫扑热帖
def parse_mop():
try:
url = "https://www.mop.com/"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}
fname = dir + "mop.json"
r = requests.get(url, headers=headers, timeout=(5, 10))
r.encoding='utf-8'
soup = etree.HTML(r.text.replace("<h3>", "").replace("</h3>", ""))
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "猫扑热帖"
for soup_a in soup.xpath("//div[@class='swiper-wrapper']")[0]:
blist = {}
hot_name = soup_a.xpath("./a/div/h2/text()")[0].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = soup_a.xpath("./a/@href")[0]
group = "mop"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
for soup_b in soup.xpath("//div[@class='shuffling-two']/a"):
blist = {}
hot_name = soup_b.xpath("./div/p/text()")[0].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = soup_b.get('href')
group = "mop"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
for soup_c in soup.xpath("//div[@class='mop-hot']/div[1]/div/div/div/div/div[2]/a"):
blist = {}
hot_name = soup_c.text.replace("\r", "").replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = soup_c.get('href')
group = "mop"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#果壳-科学人
def parse_guokr():
try:
url = "https://www.guokr.com/scientific/"
url2 = "https://www.guokr.com/beta/proxy/science_api/articles?retrieve_type=by_category&page=1"
url3 = "https://www.guokr.com/beta/proxy/science_api/articles?retrieve_type=by_category&page=2"
headers = {
'Referer': 'https://www.guokr.com/',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}
fname = dir + "guokr.json"
r = requests.get(url, headers=headers, timeout=(5, 10))
r.encoding='utf-8'
soup = etree.HTML(r.text.replace("<span class=\"split\">|</span>", ""))
r2 = requests.get(url2, headers=headers, timeout=(5, 10)).text
data2 = json.loads(r2)
r3 = requests.get(url3, headers=headers, timeout=(5, 10)).text
data3 = json.loads(r3)
list = []
jsondict= {}
list_time = soup.xpath("//div[@class='article-info']/text()")[1].replace("\"", "").strip()
jsondict["time"] = list_time
jsondict["title"] = "果壳-科学人"
for soup_a in soup.xpath("//a[@class='article-title']"):
blist = {}
hot_name = soup_a.text.replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = soup_a.get('href')
group = "guokr"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
for n in data2:
blist = {}
hot_url = "https://www.guokr.com/article/" + str(n['id']) + "/"
hot_name = n['title'].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
group = "guokr"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
for n in data3:
blist = {}
hot_url = "https://www.guokr.com/article/" + str(n['id']) + "/"
hot_name = n['title'].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
group = "guokr"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#IT之家
def parse_ithome():
try:
url = "https://www.ithome.com/"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}
fname = dir + "ithome.json"
r = requests.get(url, headers=headers, timeout=(5, 10))
r.encoding='utf-8'
soup = etree.HTML(r.text)
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "IT之家"
for soup_a in soup.xpath("//div[@class='bx']/ul/li/a"):
blist = {}
hot_name = soup_a.text.replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = soup_a.get('href')
group = "ithome"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#央视要闻
def parse_cctv():
try:
url = "http://news.cctv.com/data/index.json"
headers = {
'Referer': 'https://news.cctv.com/',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}
fname = dir + "cctv.json"
r = requests.get(url, headers=headers, timeout=(5, 10)).text
data = json.loads(r)
list = []
jsondict= {}
list_time = data['updateTime']
jsondict["time"] = list_time
jsondict["title"] = "央视要闻"
for n in data['rollData']:
blist = {}
hot_url = n['url']
hot_name = n['title'].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
group = "cctv"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#cnBeta
def parse_cnbeta():
try:
url = "https://www.cnbeta.com/"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}
fname = dir + "cnbeta.json"
r = requests.get(url, headers=headers, timeout=(5, 10))
r.encoding='utf-8'
soup = etree.HTML(r.text)
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "cnBeta"
for soup_a in soup.xpath("//div[@class='items-area']/div/dl/dt/a"):
blist = {}
hot_name = soup_a.xpath("./span/text()")
if hot_name:
hot_name = hot_name[0].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
else:
hot_name = soup_a.text.replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = soup_a.get('href').replace("//hot", "https://hot").strip()
group = "cnbeta"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#联合早报-中港台
def parse_zaobao():
try:
url = "https://www.zaobao.com.sg/realtime/china"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}
fname = dir + "zaobao.json"
r = requests.get(url, headers=headers, timeout=(5, 10))
r.encoding='utf-8'
soup = etree.HTML(r.text)
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "联合早报-中港台"
for soup_a in soup.xpath("//a[@target='_self']"):
blist = {}
hot_name = soup_a.xpath("./div/span/text()")[0].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = "https://www.zaobao.com.sg" + soup_a.get('href').strip()
group = "zaobao"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#微信公众号热门文章
def parse_weixin():
try:
url = "https://weixin.sogou.com/"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}
fname = dir + "weixin.json"
fname2 = dir + "weixin_hot.json"
r = requests.get(url, headers=headers, timeout=(5, 10))
r.encoding='utf-8'
soup = etree.HTML(r.text)
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "微信公众号搜索热词"
for soup_a in soup.xpath("//ol[@class='hot-news']/li"):
blist = {}
hot_name = soup_a.xpath("./a/text()")[0].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = soup_a.xpath("./a/@href")[0]
hot_num = soup_a.xpath("./span/span/@style")[0].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").replace("width:", "").replace("%", "").strip()
group = "weixin"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
blist["num"]=hot_num
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
list = []
jsondict= {}
jsondict["time"] = list_time
jsondict["title"] = "微信公众号热门文章"
for soup_a in soup.xpath("//div[@class='txt-box']/h3/a"):
blist = {}
hot_name = soup_a.text.replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = soup_a.get('href')
group = "weixin"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname2,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#澎湃新闻
def parse_thepaper():
try:
url = "https://www.thepaper.cn/load_chosen.jsp"
headers = {
'Referer': 'https://www.thepaper.cn/',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}
fname = dir + "thepaper.json"
r = requests.get(url, headers=headers, timeout=(5, 10))
r.encoding='utf-8'
soup = etree.HTML(r.text)
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "澎湃新闻"
for soup_a in soup.xpath("//div[@class='news_li']/h2/a"):
blist = {}
hot_name = soup_a.text.replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = "https://www.thepaper.cn/" + soup_a.get('href')
group = "thepaper"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#纽约时报中文网-国际简报
def parse_nytimes():
try:
url = "https://m.cn.nytimes.com/world"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}
fname = dir + "nytimes.json"
r = requests.get(url, headers=headers, timeout=(5, 10))
r.encoding='utf-8'
soup = etree.HTML(r.text)
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "纽约时报中文网-国际简报"
for soup_a in soup.xpath("//li[@class='regular-item']/a"):
blist = {}
hot_name = soup_a.get('title').replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = soup_a.get('href')
group = "nytimes"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#新京报-排行
def parse_bjnews():
try:
url = "http://www.bjnews.com.cn/"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}
fname = dir + "bjnews.json"
r = requests.get(url, headers=headers, timeout=(5, 10))
r.encoding='utf-8'
soup = etree.HTML(r.text)
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "新京报-排行"
for soup_a in soup.xpath("//li/h3/a"):
blist = {}
hot_name = soup_a.text.replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = soup_a.get('href')
group = "bjnews"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#奇客的资讯
def parse_solidot():
try:
url = "https://www.solidot.org/"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}
fname = dir + "solidot.json"
r = requests.get(url, headers=headers, timeout=(5, 10))
r.encoding='utf-8'
soup = etree.HTML(r.text)
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "奇客的资讯"
for soup_a in soup.xpath("//div[@class='bg_htit']/h2/a"):
blist = {}
hot_name = soup_a.text.replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = "https://www.solidot.org" + soup_a.get('href')
group = "solidot"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#新浪科技
def parse_sinatech():
try:
url = "https://feed.mix.sina.com.cn/api/roll/get?pageid=372&lid=2431&k=&num=50&page=1"
headers = {
'Referer': 'http://tech.sina.com.cn/roll/rollnews.shtml#pageid=372&lid=2431&k=&num=50&page=1',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}
fname = dir + "sinatech.json"
r = requests.get(url, headers=headers, timeout=(5, 10)).text
data = json.loads(r)
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(data['result']['data'][0]['ctime'])))
jsondict["time"] = list_time
jsondict["title"] = "新浪科技"
for n in data['result']['data']:
blist = {}
hot_url = n['url']
hot_name = n['title'].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
group = "sinatech"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#全球主机交流论坛
def parse_hostloc():
try:
url = "https://www.hostloc.com/forum.php?mod=forumdisplay&fid=45&filter=author&orderby=dateline"
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}
cookies = {'hkCM_2132_saltkey': 'YUW6N18j', 'hkCM_2132_lastvisit': '1565188564', 'hkCM_2132_visitedfid': '45', 'L7DFW': 'f64d0d1c0e4afb6b8913e5cf1d39cbf2', 'hkCM_2132_sid': 'svW2eC', 'hkCM_2132_st_t': '0%7C1565195462%7Cc9e8fe0fa2043784ed064e22c9180fb3', 'hkCM_2132_forum_lastvisit': 'D_45_1565195462', 'hkCM_2132_lastact': '1565195463%09home.php%09misc', 'hkCM_2132_sendmail': '1'}
fname = dir + "hostloc.json"
r = requests.get(url, headers=headers, cookies=cookies, timeout=(5, 10)).text.replace("<th class=\"lock\">", "<abc>")
soup = etree.HTML(r)
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "全球主机交流论坛"
for soup_a in soup.xpath("//th/a[@onclick='atarget(this)']"):
blist = {}
hot_name = soup_a.text.replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = "https://www.hostloc.com/" + soup_a.get('href')
group = "hostloc"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#什么值得买-今日热门文章
def parse_smzdm_article(name):
try:
jsondict= {}
if name=="today":
id="1"
jsondict["title"] = "什么值得买热门文章(日榜)"
if name=="week":
id="7"
jsondict["title"] = "什么值得买热门文章(周榜)"
if name=="month":
id="30"
jsondict["title"] = "什么值得买热门文章(月榜)"
url = "https://post.smzdm.com/rank/json_more/?unit="+id+"&p=1"
url2 = "https://post.smzdm.com/rank/json_more/?unit="+id+"&p=2"
headers = {
'Referer': 'https://post.smzdm.com/',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}
fname = dir + "smzdm_article_"+name+".json"
r = requests.get(url, headers=headers, timeout=(5, 10)).text
data = json.loads(r)
r2 = requests.get(url2, headers=headers, timeout=(5, 10)).text
data2 = json.loads(r2)
list = []
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
for n in data['data']:
blist = {}
hot_url = n['article_url']
hot_name = n['title'].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
group = "smzdm_article"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
for n in data2['data']:
blist = {}
hot_url = n['article_url']
hot_name = n['title'].replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
group = "smzdm_article"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"("+name+")"+"采集错误,请及时更新规则!")
#知乎每日精选-编辑推荐
def parse_zhihu_good():
try:
url = "https://www.zhihu.com/node/ExploreRecommendListV2"
headers = {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
'authority': 'www.zhihu.com',
'Referer': 'https://www.zhihu.com/explore/recommendations',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}
d = {'method': 'next', 'params': '{"limit":40,"offset":0}'}
fname = dir + "zhihu_good.json"
r = requests.post(url, data=d, headers=headers, timeout=(5, 10))
r.encoding='utf-8'
json_data = ""
list = []
jsondict= {}
list_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
jsondict["time"] = list_time
jsondict["title"] = "知乎每日精选-编辑推荐"
for json_d in json.loads(r.text)['msg']:
json_data = json_data + json_d
soup = etree.HTML(json_data)
for soup_a in soup.xpath("//div[@class='zm-item']/h2/a"):
blist = {}
hot_name = soup_a.text.replace("\\n", "").replace("\n", "").replace("\\r", "").replace("\r", "").strip()
hot_url = soup_a.get('href').replace("/question/", "https://www.zhihu.com/question/")
group = "zhihu_good"
hot_url = "get/?url=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_url.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1]) + "&group=" + group + "&title=" + multiple_replace(base64.urlsafe_b64encode(base64.urlsafe_b64encode(hot_name.encode("utf-8")).decode("utf-8").encode("utf-8")).decode("utf-8").replace("=", "")[::-1])
blist["name"]=hot_name
blist["url"]=hot_url
list.append(blist)
jsondict["data"]=list
with open(fname,"w+",encoding='utf-8') as f:
f.write(json.dumps(jsondict, ensure_ascii=False, indent=2, separators=(',',':')))
except:
print(sys._getframe().f_code.co_name+"采集错误,请及时更新规则!")
#AppStore排行榜
def parse_itunes(name,country):