
如何去除爬取网站数据中的转义字符?
针对问题中出现的 “” 和 “
” 等转义字符,可以通过以下方法将其去除:
1.使用正则表达式:
import rehtml = "(.*)
"dr = re.compile(r']+>', re.s) contant =re.findall(findcontant1, item)if len(contant) <= 0: contant = re.findall(findcontant2, item)contant = dr.sub('', str(contant))
2.使用beautifulsoup进行解析:
from bs4 import BeautifulSoupimport rehtml = "(.*)
"soup = BeautifulSoup(html, "html.parser")contant = soup.find('p').text
经过上述处理,即可去除转义字符,获得干净的文本内容。
以上就是如何去除爬取网站数据中的转义字符?的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1351933.html
微信扫一扫
支付宝扫一扫