修改并写了新的知乎剪藏模版obsidian web clipper

  • 在@aoout佬的这个脚本基础上修改:写了一个官方 clipper 的知乎回答剪藏模板(去除知乎 ai 链接,获取作者和发布时间)

  • 25年9月20号增加几个功能点:

    • 使用CSS选择器,剔除掉所有无关的内容比如多少人赞同、更多回答。专注于回答的内容本身
    • 使用CSS选择器,获取回答的发布时间,添加进属性变量
    • 使用CSS选择器,获取回答的赞同数量,添加进属性变量
    • 使用replace,替换掉标题中偶尔出现的(X封私信)
    • 参考@probe佬的回复,剔除掉正文中恶心的知乎关键词解释
    • 顺便修改正文内容选择器,现在使用更准确的内容定位
  • 以下是配置JSON代码:

{
  "schemaVersion": "0.1.0",
  "name": "知乎回答 (7)",
  "behavior": "create",
  "noteContentFormat": "{{selectorHtml:.QuestionAnswer-content .RichText|replace:\"href=\\\"https\\://zhida\":\"\"|markdown}}",
  "properties": [
    {
      "name": "source",
      "value": "{{url}}",
      "type": "text"
    },
    {
      "name": "author",
      "value": "{{selector:.UserLink-link|slice:1,2}}",
      "type": "multitext"
    },
    {
      "name": "publicTime",
      "value": "{{selector:.QuestionAnswer-content .ContentItem-time span}}",
      "type": "text"
    },
    {
      "name": "agreeCount",
      "value": "{{selector:.RichContent-actions .VoteButton--up}}",
      "type": "text"
    }
  ],
  "triggers": [
    "https://www.zhihu.com/question/*/answer"
  ],
  "noteNameFormat": "{{title|replace:\" - 知乎\":\"\"|replace:/^\\(.*?\\)/g, \"\"}}",
  "path": "00_inbox"
}
  • 上面配置的导入方式:
    新用户只能上传一幅图,自己找吧(

  • 效果展示图,原文章地址

9 个赞

话说评论和图片有办法获取吗

敢尝试了下,效果不错。不过知乎专栏不能剪切。另外大佬,如果学写这类脚本的话,除了您推荐的的两个链接外还有哪些知识要了解?

1 个赞

可以看看web clipper的文档,value那里应该是类似于css选择器的那种语法,format格式化那里用的是正则语法.

这是我之前改的知乎专栏的写法(元数据都改成符合我的习惯的了),不知道现在还有没有用你可以试试看(之前跟楼主这个知乎回答一起用好像会分不清优先级,还没解决这个问题,手动选吧):

{
	"schemaVersion": "0.1.0",
	"name": "知乎专栏",
	"behavior": "create",
	"noteContentFormat": "{{content}}",
	"properties": [
		{
			"name": "source",
			"value": "{{domain}}",
			"type": "text"
		},
		{
			"name": "source-url",
			"value": "{{url}}",
			"type": "text"
		},
		{
			"name": "source-title",
			"value": "{{title|replace:\\\" - 知乎\\\":\\\"\\\"|replace:\\\"/\\(\\d+\\s*封私信\\)/g\\\":\\\"\\\"}}",
			"type": "text"
		},
		{
			"name": "author",
			"value": "{{selector:.UserLink-link|slice:1,2}}",
			"type": "multitext"
		},
		{
			"name": "publicTime",
			"value": "{{selector:.Post-Row-Content .ContentItem-time}}",
			"type": "text"
		},
		{
			"name": "agreeCount",
			"value": "{{selector:.RichContent-actions .VoteButton--up}}",
			"type": "text"
		},
		{
			"name": "description",
			"value": "{{description}}",
			"type": "text"
		},
		{
			"name": "tags",
			"value": "clippings",
			"type": "multitext"
		},
		{
			"name": "year",
			"value": "{{date|date:\\\"YYYY\\\"}}",
			"type": "text"
		}
	],
	"triggers": [
		"https://zhuanlan.zhihu.com/p/"
	],
	"noteNameFormat": "{{title|replace:\" - 知乎\":\"\"|replace:\"/\\(\\d+\\s*封私信\\)/g\":\"\"}}",
	"path": "你的仓库地址"
}
1 个赞

这个论坛的密码搞忘了,见谅这么久回复

  • 目前这两个功能不好搞,涉及评论区的加载和图片的保存本来就不是markdown的强项
  • 另外更新了一波这个模版,现在是0.3.0版本,主要解决一些垃圾消息的替换问题

图片还好,之前读不到好像是因为知乎套的图片标签没适配好,之前给转md的那个项目提了issue,现在已经能正常拿图片链接了 :joy: :rofl:

这个是怎么实现的?我都是用油猴脚本禁掉高亮的 :rofl:

css选择器标签替换功能,你把你的问题和我的脚本提供给大模型解答即可。