【发布时间】:2020-10-05 11:16:10
【问题描述】:
我想获取网页的所有文本,因此我尝试将 html2text 模块与 urllib.request 模块一起使用--
import urllib.request
import html2text
request_url = urllib.request.urlopen('https://dev.to/justdevasur/let-s-perform-google-search-with-python-2gpi')
u=request_url.read()
print(html2text.html2text(u))
print('Done')
但我收到以下错误--
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\rauna\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\html2text\__init__.py", line 947, in html2text
return h.handle(html)
File "C:\Users\rauna\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\html2text\__init__.py", line 142, in handle
self.feed(data)
File "C:\Users\rauna\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\html2text\__init__.py", line 138, in feed
data = data.replace("</' + 'script>", "</ignore>")
TypeError: a bytes-like object is required, not 'str'
【问题讨论】:
标签: python python-3.x web-scraping urllib3