python - python获取URL的明文数据

标签 python url fetch plaintext

我想从给定的 URL 获取纯文本(例如,没有 html 标签和实体)。 我应该使用什么库来尽快做到这一点?

我已经尝试过(也许有比这更快或更好的东西):

import re
import mechanize
br = mechanize.Browser()
br.open("myurl.com")
vh = br.viewing_html
//<bound method Browser.viewing_html of <mechanize._mechanize.Browser instance at 0x01E015A8>>

谢谢

最佳答案

您可以使用HTML2Text如果该网站不适合您,您可以访问 HTML2Text github Repo并获取 Python 版本

或者试试这个:

import urllib
from bs4 import*

html = urllib.urlopen('myurl.com').read()
soup = BeautifulSoup(html)
text = soup.get_text()
print text

我不知道它是否摆脱了所有的js和东西,但它摆脱了HTML

Google 搜索一下,发现还有多个与此类似的其他问题

也可以看看 Read2Text

关于python - python获取URL的明文数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17769896/

相关文章:

python - 如何在 put_object 中指定标记?

c# - WebBrowser 保持 url/uri 编码不解码

iphone - 获取常量值 : unrecognized selector sent to instance error

react-native - React Native 的 fetch 缓存行为是什么

javascript - Python:实际上可以在 splitter 中访问文件上传吗?

python - 从 Django 表单集中删除表单

python - 如果我们知道在先字符,则计算 Python 中的字符出现次数

php - 将参数传递给 jquery javascript 函数?

java - 禁止 Java URL 获取本地文件?

mysql - 将自己排除在友谊页面之外 - MySQL