如何解决维基百科的站点摘要提要,不包括单个用户
维基百科主页上有一个“最近的变化”供稿。
同样也可用作 ATOM 提要。也可以通过转到他们的 user_account 并选择提要来观看单个用户。 但是,除了一(或两个)用户之外,有没有办法访问提要?
更新:使用 xmllint 我可以提取作者姓名。
wget https://hunspell.s3.amazonaws.com/temp/out.txt
xmllint --xpath "//*[name() = 'feed']/*[name() = 'entry']/*[name() = 'author']/*[name() = 'name']" out.txt
但我想从这个提要中排除一两个作者。例如,Clarityfiend 和 Shortride。
更新:
当我尝试 xpath 命令时,它使用一个参数(英文)运行良好。但它以 Unicode 参数失败:
wget https://hunspell.s3.amazonaws.com/todel/out.txt
工作:
xpath -e "/feed/entry[author/name!='Aditya tamhankar' and author/name!='Sushant Madhale']" out.txt > a.txt
没有用:
xpath -e "/feed/entry[author/name!='Aditya tamhankar' and author/name!='संतोष गोरे']" out.txt > filtered.txt
第二作者的条目仍然存在于过滤输出中。
grep 'संतोष गोरे' filtered.txt
第二个命令对 Unicode 没问题,但它没有正确显示一条记录...
# (t1='Aditya tamhankar' ; t2='संतोष गोरे'; echo 'setns x=http://www.w3.org/2005/Atom'; echo "cat /x:feed/x:entry[not(x:author/x:name[.='$t1'] | x:author/x:name[.='$t2'])]/descendant::*[self::x:updated or self::x:title or descendant-or-self::x:name]/text()") | xmllint --shell out.txt | tail -n +4 | gawk '{ if(NR % 6 == 0){ print $0 "¬"} else { print $0 }}' |gawk 'BEGIN{FS="\n -------\n" ; RS="\n -------¬\n"; OFS="||"} { print $2,$1,$3 }END{ print FNR}'
除此之外的所有记录都是正确的:
152.238.27.63
/ >
||2021-07-15T20:14:03Z||
19
解决方法
您可以安装 AbuseFilter 并定义一个规则,该规则将 tag 由除一两个用户之外的所有用户进行的编辑(使用变量 user_name
过滤。
然后您可以使用该标签过滤最近的更改。标记最近更改的 Atom 提要的 URL,例如“Android 应用编辑”将如下所示:https://en.wikipedia.org/w/api.php?tagfilter=android+app+edit&urlversion=1&action=feedrecentchanges&feedformat=atom。
这当然是成立的,如果您的意思不是维基百科而是您控制的维基。
或
您可以提供所有最近的更改(例如 https://en.wikipedia.org/w/api.php?urlversion=1&action=feedrecentchanges&feedformat=atom)并使用 /feed/entry[author/name[text()!='Linason Blessing']]
之类的 XPath 过滤它们以排除 Linason Blessing 的更改。请参阅saved XPath。
我建议您使用终端中的 xpath
工具(Ubuntu 软件包 libxml-xpath-perl
)。它支持 XPath 2:
wget -O - https://hunspell.s3.amazonaws.com/temp/out.txt | xpath -e "/feed/entry[author/name!='Clarityfiend' and author/name!='Shortride']" > filtered.txt
UPD:如果输入缓冲区出现内存不足错误,请将提要下载到文件而不是标准输出中:
wget https://hunspell.s3.amazonaws.com/temp/out.txt
xpath -e "/feed/entry[author/name!='Clarityfiend' and author/name!='Shortride']" out.txt > filtered.txt
XPath 查询将列出作者姓名不等于 Clarityfiend 或 Shortride 的所有条目。条目将保存在 filtered.txt
中。
使用 xmllint
的 Bash one-liner 将通过 author/name
过滤,其中包含 t1
和 t2
变量中定义的 2 个字符串并输出 update||title||author
值>
(t1='संतोष गोरे' ; t2='ñandú'; echo 'setns x=http://www.w3.org/2005/Atom'; echo "cat /x:feed/x:entry[not(x:author/x:name[contains(text(),'$t1')] | x:author/x:name[contains(text(),'$t2')])]/descendant::*[self::x:updated or self::x:title or descendant-or-self::x:name]/text()") | xmllint --shell wiki.xml | tail -n +3 | gawk '!/ -------/ { if(NR % 3 == 0){ $0=$0 "\n"}else{$0=$0} { print }}' | gawk 'BEGIN{FS="\n";RS="\n\n"; OFS="||"} { print $2,$1,$3 }END{ print FNR}'
过滤表达式类型:x:author/x:name[not(contains(text(),'$t1'))]
结果:
2021-07-15T22:34:54Z||Fabiano Leismann||Simione001
2021-07-15T22:34:53Z||Arnold Henry Mason||4meter4
2021-07-15T22:34:53Z||User talk:MrOllie||152.168.57.106
...
...
这会做同样的事情,但在 author
(t1='संतोष गोरे' ; t2='ñandú'; echo 'setns x=http://www.w3.org/2005/Atom'; echo "cat /x:feed/x:entry[not(x:author/x:name[.='$t1'] | x:author/x:name[.='$t2'])]/descendant::*[self::x:updated or self::x:title or descendant-or-self::x:name]/text()") | xmllint --shell wiki.xml | tail -n +3 | gawk '!/ -------/ { if(NR % 3 == 0){ $0=$0 "\n"}else{$0=$0} { print }}' | gawk 'BEGIN{FS="\n"; RS="\n\n"; OFS="||"} { print $2,$3 }END{ print FNR}'
过滤表达式类型:x:author/x:name[not(.='$t1')]
仅过滤一位作者:
(t1='संतोष गोरे'; echo 'setns x=http://www.w3.org/2005/Atom'; echo "cat /x:feed/x:entry[not(x:author/x:name[.='$t1'])]/descendant::*[self::x:updated or self::x:title or descendant-or-self::x:name]/text()") | xmllint --shell wiki.xml | tail -n +3 | gawk '!/ -------/ { if(NR % 3 == 0){ $0=$0 "\n"}else{$0=$0} { print }}' | gawk 'BEGIN{FS="\n"; RS="\n\n"; OFS="||"} { print $2,$3 }END{ print FNR}'
或者生成一个 UUID 并将其分配给 t2
;-)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。