python - 过滤网站上的特定评论
问题描述
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
#import re
from BeautifulSoup import BeautifulSoup
headers = {'User-Agent': 'Mozilla/5.0'}
req = urllib2.Request('https://www.sikayetvar.com/onedio',
None,headers)
resp = urllib2.urlopen(req)
html = resp.read()
soup = BeautifulSoup(html)
complaints = soup.findAll('p', attrs = {'class' : 'complaint-summary'})
for complaint in complaints:
if complaint.text.find("genç") is not -1:
print complaint.text
我想在网站上过滤某些包含特定单词的投诉,但我无法搜索其中包含非 ASCII 字符的单词。我正在使用 python 2.7 和 beautifulsoup。知道为什么会这样吗?
解决方案
如果您的测试在 p 标签内,YouTube 应该将 od 语句更改为
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
from BeautifulSoup import BeautifulSoup
headers = {'User-Agent': 'Mozilla/5.0'}
req = urllib2.Request('https://www.sikayetvar.com/onedio',
None,headers)
resp = urllib2.urlopen(req)
html = resp.read()
soup = BeautifulSoup(html)
complaints = soup.findAll('p', attrs = {'class' : 'complaint-summary'})
for complaint in complaints:
if b"genç".decode("utf-8") in complaint.text:
print(complaint.text)
推荐阅读
- php - MongoDB\Exception\InvalidArgumentException
- c# - C# COM 对象重新分配处理
- realsense - 如何在 Intel Realsense D435 深度图像中检测精确深度
- java - 设置内部私有面板不透明
- servicenow - 检索客户端软件分发服务的 SCCM 数据现在
- java - 如何停止反应堆 websocket 连接
- javascript - 如何从正则表达式中排除最后一个空格?
- html - Angular:如何在数组中仅显示一次重复字段并在鼠标悬停时显示内容?
- python - aws cdk python:将 codedeploy 操作作为阶段添加到 codepipeline 时出错(jsii.errors.JSIIError:无法读取未定义的属性“区域”)
- regex - RegEx 以特定顺序的正向前瞻