Python-从位置开始打印文本(html)

Python-从位置开始打印文本(html),python,Python,我试图从html文本中搜索一个单词,即meta,并从该单词的位置开始打印以下20个字符 以下代码不返回任何内容: import os,sys,urllib.request url = "http://www.google.com/" req = urllib.request.Request(url) response = urllib.request.urlopen(req) html = response.read() html2 = html.decode("windows-1252") b

我试图从html文本中搜索一个单词,即meta,并从该单词的位置开始打印以下20个字符

以下代码不返回任何内容:

import os,sys,urllib.request
url = "http://www.google.com/"
req = urllib.request.Request(url)
response = urllib.request.urlopen(req)
html = response.read()
html2 = html.decode("windows-1252")
b2='meta'
position=html2.index(b2)
if b2 in html2:
    print(html2[position:20])

只需将代码更改为:

print(html2[position: position + 20])
在最后一行尝试printhtml2[位置:位置+20]