You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hunjianghu/gzy/tesorflow/KMP用于网页内容匹配.py

25 lines
594 B

nexts = [0]*100
x = '<img class="ui image bqppsearch lazy" data-original="'
def KMPinit():
i,j,m = 0,-1,len(x)
nexts[0]=-1
while i<m:
while j!=-1 and x[i]!=x[j]: j=nexts[j]
nexts[i+1]=j+1
i,j=i+1,j+1
def findWord(y):
i,j,ans,n,m=0,0,[],len(y),len(x)
while i<n:
while j!=-1 and y[i]!=x[j]: j=nexts[j]
i,j=i+1,j+1
if j==m:
to = i+1
while y[to:to+7]!='\" title': to=to+1
if y[to-3:to]=='jpg' and y[i]=='h' :ans.append(y[i:to])
j=nexts[j]
return ans