Skip to content

Commit 686311a

Browse files
committed
修改了bug
为爬虫正式全面使用selenium 为数据库大小写会区分的问题进行了修改
1 parent 09a35a7 commit 686311a

4 files changed

Lines changed: 41 additions & 46 deletions

File tree

resources/Spider/CDS-Distributed.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
from CDS_Selenium import *
2525
import time
2626

27+
# -- selenium --
28+
chrome_options = webdriver.ChromeOptions()
29+
prefs={"profile.managed_default_content_settings.images":2}
30+
chrome_options.add_experimental_option("prefs",prefs)
31+
# -- end selenium --
32+
2733
cube = CubeQL_Client.CubeQL()
2834

2935
hea_ordinary = {
@@ -102,6 +108,11 @@ def postgresql_initation(): # 这边是postgres的版本
102108
def togbk(string):
103109
return string.encode("gbk")
104110

111+
def get_url_code(url):
112+
driver = webdriver.Chrome(chrome_options=chrome_options)
113+
driver.get(url)
114+
115+
return driver.page_source
105116

106117
def delcssjs(code):
107118
while code.find("<style>") != -1:
@@ -116,7 +127,7 @@ def delcssjs(code):
116127
return code
117128

118129

119-
def gethtmurl(url):
130+
def get_url(url):
120131
soup = BeautifulSoup(url, "html.parser")
121132
ret = []
122133
href_ = soup.find_all(name="a")
@@ -199,12 +210,12 @@ def weigh_judgement(url, urlcode):
199210

200211

201212
def getsearchurl(keyword):
202-
url = requests.get(
213+
url = get_url_code(
203214
"http://mijisou.com/?q="
204215
+ keyword
205216
+ "&category_general=on&time_range=&language=zh-CN&pageno=1",
206217
hea_ordinary,
207-
).text
218+
)
208219
print(url)
209220
soup = BeautifulSoup(url, "html.parser")
210221
ret = []
@@ -254,17 +265,15 @@ def mainly():
254265
# 用来判断这个url有没有被爬过,通过cubeql里面的filter
255266
#0.1.5已经废除在爬虫使用这个逻辑,改到cubeql了
256267

257-
req = requests.get(destination_URI, hea)
258-
req.encoding = 'utf-8'
268+
259269

260270
if destination_URI in dictlist:
261271
continue
262272
if destination_URI.find(".png") != -1:
263273
continue
264-
if req.status_code != 200: # 0.12内容,如果网页不返回200,就不载入数据库
265-
continue
266-
code = req.text # urllib.request.urlopen(req).read()
267-
geturls = gethtmurl(code)
274+
275+
code = get_url_code(destination_URI)
276+
geturls = get_url(code)#获取该页面的所有子链接
268277
# 取body做为内容
269278
maincontent = get_keywords(code) + " " + get_p_content(code)
270279
title = get_title(code)
@@ -347,6 +356,7 @@ def mainly():
347356
print(destination_URI, " :end")
348357
# ---------------------------------------------
349358
elif i["typ"] == "search":
359+
continue
350360
destination_URI = i["content"]
351361
mijisou(destination_URI)
352362
print(destination_URI, " :end")
@@ -357,18 +367,14 @@ def mainly():
357367
if cube.filter_contain(destination_URI) == "1":
358368
continue
359369

360-
req = requests.get(destination_URI, hea)
361-
req.encoding = req.apparent_encoding
362-
if req.apparent_encoding.find("ISO") != -1:
363-
req.encoding = "utf-8"
370+
364371
if destination_URI in dictlist:
365372
continue
366373
if destination_URI.find(".png") != -1:
367374
continue
368-
if req.status_code != 200: # 0.12内容,如果网页不返回200,就不载入数据库
369-
continue
370-
code = req.text # urllib.request.urlopen(req).read()
371-
geturls = gethtmurl(code)
375+
376+
code = get_url_code(destination_URI)
377+
geturls = get_url(code)
372378
# 取body做为内容
373379
maincontent = get_keywords(code) + " " + get_p_content(code)
374380
title = get_title(code)

resources/Spider/CDS_Selenium.py

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,19 @@
44
from selenium import webdriver
55
from bs4 import BeautifulSoup
66
from CubeQL_Client import CubeQL
7+
chrome_options = webdriver.ChromeOptions()
8+
prefs={"profile.managed_default_content_settings.images":2}
9+
chrome_options.add_experimental_option("prefs",prefs)
710
def mijisou(keyword):
8-
driver = webdriver.Chrome()
9-
driver.get(r'https://mijisou.com/?q='+keyword+'&category_general=on&time_range=&language=zh-CN&pageno=1')
11+
driver = webdriver.Chrome(chrome_options=chrome_options)
12+
driver.get(r'https://blog.csdn.net/weixin_42066185/article/details/81675726')
1013
#可能需要等待js加载完毕
1114

12-
soup = BeautifulSoup(driver.page_source, "html.parser")
13-
href_ = soup.find_all(name="h4")
14-
for each in href_:
15-
# print(each.get('rel'))
16-
if each.get("class") == ['result_header']:#["noopener", "noreferrer"]:
17-
18-
if each.a.get('href').find('mijisou')!=-1:
19-
#如果发现是proxy网页不能直接进去,就不要了
20-
continue
21-
print(each.a.get('href'))
22-
print(each.text)
23-
cube = CubeQL()
24-
cube.set(each.a.get('href'),'fromsearch')
15+
print(driver.page_source)
2516

2617
'''
2718
秘迹搜有两个标签特点
2819
第一个是result-header,a标签的href是网址,内容是标题,带有高亮标签
2920
第二个是result-content, 内容有高亮标签,内容也是简介,可以直接存进database
30-
这个是青荇搜索自我学习爬虫的一部分功能,对其他搜索引擎进行爬虫
31-
青荇搜索还可以通过不同领域进行不同结果的展示
32-
- 英文文献页面 并且支持文本翻译后打开
33-
- IT页面,支持对计算机方面(github,csdn,stackoverflow等网站)customed Spider(定制化爬虫)
34-
35-
Customed Distributed Spider 定制化分布式爬虫
36-
- 英语词典爬虫
37-
- 综合搜索引擎爬虫
38-
- 不同领域不同网页的定制爬虫
3921
'''
22+
mijisou('a')

resources/backend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def search():
202202
amount = int(amount)
203203
end_amount = int(amount) + 10
204204
length = 0
205-
cursor.execute("select value from search where keyer = %s;", (keyword,))
205+
cursor.execute("select value from search where keyer ~* %s;", (keyword,))
206206
ret = cursor.fetchone()
207207

208208
response_json = {}
@@ -241,7 +241,7 @@ def search():
241241
match_weigh = {}
242242
tmp_index_list = {}
243243
for i in res_:
244-
cursor.execute("select value from search where keyer = %s", (i,))
244+
cursor.execute("select value from search where keyer ~* %s", (i,))
245245
fetch = cursor.fetchone()
246246
if fetch == None:
247247
continue
@@ -292,7 +292,7 @@ def search():
292292
else:
293293
# 新增关键词权值统计
294294
cursor.execute(
295-
"update search set weigh = weigh + 1 where keyer = %s", (keyword,)
295+
"update search set weigh = weigh + 1 where keyer ~* %s", (keyword,)
296296
)
297297
mysql.commit()
298298
index_list = ret[0].split("|")

sql/content.sql

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Target Server Type : PGSQL
1111
Target Server Version : 111000
1212
File Encoding : 65001
1313
14-
Date: 2021-01-31 16:21:44
14+
Date: 2021-02-06 00:15:17
1515
*/
1616

1717

@@ -678,7 +678,7 @@ INSERT INTO "public"."content" VALUES ('14', 'http://news.baidu.com', '百度新
678678

679679
搜索
680680
扫描二维码, 收看更多新闻 ', '百度新闻——海量中文资讯平台', '32');
681-
INSERT INTO "public"."content" VALUES ('15', 'http://www.baidu.com', ' 关于百度 About Baidu ©2017 Baidu 使用百度前必读  意见反馈 京ICP证030173号  ', '百度一下,你就知道', '55');
681+
INSERT INTO "public"."content" VALUES ('15', 'http://www.baidu.com', ' 关于百度 About Baidu ©2017 Baidu 使用百度前必读  意见反馈 京ICP证030173号  ', '百度一下,你就知道', '56');
682682
INSERT INTO "public"."content" VALUES ('16', 'http://www.hao123.com', '上网导航,网址大全,网址导航,hao123上网导航,hao123网址,hao123导航,hao123网址大全,hao123活动, 抽奖活动hao123是汇集全网优质网址及资源的中文上网导航。及时收录影视、音乐、小说、游戏等分类的网址和内容,让您的网络生活更简单精彩。上网,从hao123开始。 内容加载中... ', 'hao123_上网从这里开始', '22');
683683
INSERT INTO "public"."content" VALUES ('17', 'http://app.hao123.com/app', '上网导航,网址大全,网址导航,hao123上网导航,hao123网址,hao123导航,hao123网址大全,hao123活动, 抽奖活动hao123是汇集全网优质网址及资源的中文上网导航。及时收录影视、音乐、小说、游戏等分类的网址和内容,让您的网络生活更简单精彩。上网,从hao123开始。 内容加载中... ', 'hao123_上网从这里开始', '24');
684684
INSERT INTO "public"."content" VALUES ('18', 'http://pan.baidu.com', '网盘,百度网盘,网络U盘,网络硬盘,免费网盘,网盘下载,网盘资源,同步,云存储,外链分享,离线下载百度网盘为您提供文件的网络备份、同步和分享服务。空间大、速度快、安全稳固,支持教育网加速,支持手机端。现在注册即有机会享受15G的免费存储空间 安全存储 生活井井有条 在线预览 文件即开即看 多端并用 数据随身携带 好友分享 共度幸福时光 ', '百度网盘,让美好永远陪伴', '34');
@@ -1975,6 +1975,12 @@ INSERT INTO "public"."content" VALUES ('38', 'http://iapp.org/connect/data-priva
19751975
19761976
Data Privacy Day
19771977
', '16');
1978+
INSERT INTO "public"."content" VALUES ('39', 'http://play.mcmod.cn', '我的世界服务器,Minecraft服务器,我的世界,minecraft一个专注于提高玩家体验的服务器列表,你可以在这里按MOD、服务器配置、服务器人数等信息筛选自己想要找的我的世界服务器。 总收录 1174 台服务器, 631 台运行中。 当前 6853 名玩家正在游戏中。 工业时代2 安装率: 54.89% (275台) 应用能源2 安装率: 53.09% (266台) 热力基本 安装率: 40.52% (203台) 热力膨胀4 安装率: 39.92% (200台) 通用机械 安装率: 33.93% (170台) 重力装甲 安装率: 32.34% (162台) 末影接口 安装率: 32.34% (162台) 热动力学 安装率: 32.14% (161台) 沉浸工程 安装率: 31.14% (156台) 更多存储单元2 安装率: 27.74% (139台) 植物魔法 安装率: 49.3% (247台) 神秘时代 安装率: 38.32% (192台) 额外植物学 安装率: 35.53% (178台) 神秘工匠 安装率: 25.75% (129台) 神秘能源 安装率: 20.96% (105台) 禁忌魔法 安装率: 16.97% (85台) 星辉魔法 安装率: 15.97% (80台) 等价交换重制版 安装率: 12.18% (61台) 污秽魔法 安装率: 11.78% (59台) 神秘基础学 安装率: 7.78% (39台) 更多箱子 安装率: 52.69% (264台) 匠魂2 安装率: 44.11% (221台) 无尽贪婪 安装率: 32.53% (163台) 龙之进化/龙之研究 安装率: 32.14% (161台) 储物抽屉 安装率: 24.95% (125台) 匠魂工具升级 安装率: 18.56% (93台) 更多实用设备2 安装率: 17.17% (86台) 加速火把 安装率: 16.77% (84台) 懒人厨房 安装率: 15.37% (77台) 更好的建筑之杖 安装率: 14.17% (71台) 拔刀剑 安装率: 30.34% (152台) 暮色森林 安装率: 24.95% (125台) 最后的太刀匠人 安装率: 14.57% (73台) 稀有精英怪 安装率: 12.57% (63台) 尼格洛兹·无尽曈曚 安装率: 11.38% (57台) 似蛭 安装率: 10.78% (54台) 僵尸意识 安装率: 10.78% (54台) 盖亚魔典3 安装率: 10.58% (53台) 拔刀剑日系附属包 安装率: 10.58% (53台) 冰火传说 / 冰与火之歌 安装率: 7.78% (39台) 潘马斯农场 安装率: 37.13% (186台) 林业 安装率: 29.14% (146台) 食物工艺 安装率: 9.78% (49台) 茶风·纪事 安装率: 8.18% (41台) 神秘农业 安装率: 7.78% (39台) 🍳 料理工艺 安装率: 7.19% (36台) 基因工程 安装率: 7.19% (36台) 农业工艺 安装率: 6.59% (33台) 神秘农业扩展 安装率: 6.19% (31台) 枫树 安装率: 5.79% (29台) MrCrayfish的家具 安装率: 25.55% (128台) 凿子 安装率: 21.36% (107台) 竹/饭 安装率: 17.37% (87台) 时装工坊 安装率: 16.57% (83台) 收藏馆 安装率: 14.37% (72台) 超多生物群系 安装率: 13.77% (69台) Forge Multipart CBE/ForgeMultipart 安装率: 12.97% (65台) 雕凿工艺 安装率: 8.18% (41台) 植物学 安装率: 7.19% (36台) 更多树 安装率: 7.19% (36台) ©Copyright MC百科 2013-2021 mcmod.cn |  鄂ICP备11010313号-2  鄂公网安备 42030302000264号 [浏览器: 计算中..] MC百科(mcmod.cn) 除自定义规则的文章或页面, 及未经授权的站外图片/链接以外, 所有开放公共编辑的内容, 均使用 BY-NC-SA 3.0 协议。 ', '我的世界服务器列表 - 找服玩|Minecraft服务器列表', '20');
1979+
INSERT INTO "public"."content" VALUES ('40', 'http://www.mcmod.cn/jump/service-ad', ' ��������������֧����ת,�������. ', '�Ա���ת', '19');
1980+
INSERT INTO "public"."content" VALUES ('41', 'http://bbs.mcmod.cn/thread-1500-1-1.html', ' PHP Debug ', 'bbs.mcmod.cn - System Error', '18');
1981+
INSERT INTO "public"."content" VALUES ('42', 'http://bbs.mcmod.cn', ' PHP Debug ', 'bbs.mcmod.cn - System Error', '21');
1982+
INSERT INTO "public"."content" VALUES ('43', 'http://bbs.mcmod.cn/thread-4731-1-1.html', ' PHP Debug ', 'bbs.mcmod.cn - System Error', '19');
1983+
INSERT INTO "public"."content" VALUES ('44', 'http://bbs.mcmod.cn/thread-4680-1-1.html', ' PHP Debug ', 'bbs.mcmod.cn - System Error', '18');
19781984

19791985
-- ----------------------------
19801986
-- Alter Sequences Owned By

0 commit comments

Comments
 (0)