新增: DeepSeek 全部 33 篇官方论文(原文 PDF 走 Git LFS + 中文精读笔记与索引)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
"""Print HTML context around a keyword.
|
||||
|
||||
Usage: python ctx.py <url> <keyword> [window]
|
||||
"""
|
||||
import urllib.request
|
||||
import sys
|
||||
import re
|
||||
|
||||
UA = 'Mozilla/5.0 (compatible; paperbot/1.0)'
|
||||
url = sys.argv[1]
|
||||
kw = sys.argv[2]
|
||||
win = int(sys.argv[3]) if len(sys.argv) > 3 else 600
|
||||
req = urllib.request.Request(url, headers={'User-Agent': UA})
|
||||
t = urllib.request.urlopen(req, timeout=40).read().decode('utf-8', 'ignore')
|
||||
idx = 0
|
||||
n = 0
|
||||
while True:
|
||||
i = t.find(kw, idx)
|
||||
if i < 0:
|
||||
break
|
||||
n += 1
|
||||
print('--- occurrence %d at %d ---' % (n, i))
|
||||
print(t[max(0, i - win):i + win])
|
||||
idx = i + 1
|
||||
if n >= 5:
|
||||
break
|
||||
print('occurrences found:', n)
|
||||
Reference in New Issue
Block a user