querylist采集微信公众号文章(import_module采集模块实现公众号文章的入口逻辑)
优采云 发布时间: 2022-03-15 22:14querylist采集微信公众号文章(import_module采集模块实现公众号文章的入口逻辑)
因为采集器有两种不同的实现方式,ruia和playwright,使用哪一种由配置文件决定,然后通过import_module方法动态导入对应的模块,然后运行模块的run方法,从而实现文章的公众号 bool:
"""
采集器工厂函数
:param collect_type: 采集器类型
:param collect_config: 采集器配置
:return:
"""
collect_status = False
try:
# import_module方法动态载入具体的采集模块
collect_module = import_module(f"src.collector.{collect_type}")
collect_status = collect_module.run(collect_config)
except ModuleNotFoundError:
LOGGER.error(f"采集器类型不存在 {collect_type} - {collect_config}")
except Exception as e:
LOGGER.error(f"采集器执行出错 {collect_type} - {collect_config} - {e}")
return collect_status
编剧采集模块实现
Playwright 是微软出品的自动化库。它类似于硒。它定位于网页测试,但也被人们用来获取网页信息。当然,一些前端的反爬措施,编剧是无法突破的。
与selenium相比,playwright支持python的async,性能有所提升(但还是比不上直接请求)。下面是获取公众号下最新= cos_value else 0
max_pro = value if value > max_pro else max_pro
if result == 1:
break
return {"result": result, "value": max_pro}
<p>余弦值的具体操作逻辑在CosineSimilarity的calculate方法中,都是和数学有关的,我就不看了。核心是判断当前