【发布时间】:2019-01-18 15:59:50
【问题描述】:
我是一名学习者,我使用 Python 3.7。
据我了解,find 函数应该指示字符串的索引位置。
当我的输入是像这样的直字符串时,它会这样做
myString='Blabla<body>blabla'.
现在
myString.find('<body>')
返回 6。 惊人的。 但是当我从网页导入字符串时,我得到了错误
TypeError: argument should be integer or bytes-like object, not 'str'
我完全同意,但我不明白为什么这个论点首先是str。
我的代码:
import ssl, urllib.request
url = 'http://help.websiteos.com/websiteos/example_of_a_simple_html_page.htm'
response = urllib.request.urlopen(url)
Content = response.read()
startposition = Content.find('<body>')
print(startposition)
【问题讨论】:
标签: python python-3.x