以前は文字列でキーワードを検索できましたが、リストを使用して検索すると問題が発生します。このエラーが発生し続けます。
TypeError: 'in <string>' requires string as left operand, not bool
私は考えられるすべての解決策を試しましたが、これが私が今いるところです:
from BeautifulSoup import BeautifulSoup
import urllib2
keywords = ['diy','decorate', 'craft', 'home decor', 'food']
def get_tags(blog_soup):
tags_html = blog_soup.find('div', attrs = {'style': 'margin-left: 60px; margin-bottom: 15px;'})
tags = [tag.string for tag in tags_html.findAll('a')]
string_tags = str(' '.join(tags))
if any(keywords) in string_tags:
print url
url = 'http://technorati.com/blogs/blog.mjtrim.com'
soup = BeautifulSoup(urllib2.urlopen(url).read())
get_tags(soup)