目前,我使用以下代码对网站进行分析:
import json
from os.path import join, dirname
from watson_developer_cloud import AlchemyLanguageV1
alchemy_language = AlchemyLanguageV1(api_key='YOUR API KEY')
url = 'https://developer.ibm.com/watson/blog/2015/11/03/price-reduction-
for-watson-personality-insights/'
combined_operations = ['page-image', 'entity', 'keyword', 'title',
'author', 'taxonomy', 'concept', 'doc-emotion']
print(json.dumps(alchemy_language.combined(url=url,
extract=combined_operations), indent=2))
有谁能告诉我如何引用我自己的html文件进行分析的本地目录?我尝试使用以下代码,但它无法正常工作:
#html ='C:\Users\Downloads\Python\name8.htm'
答案 0 :(得分:0)
使用html
时,您需要提供一个包含要分析的HTML代码的字符串变量。在您的代码中,您正在尝试使用文件路径作为内容。显然,这不是HTML代码。
尝试:
import json
from os.path import join, dirname
from watson_developer_cloud import AlchemyLanguageV1
alchemy_language = AlchemyLanguageV1(api_key='YOUR API KEY')
combined_operations = ['page-image', 'entity', 'keyword', 'title',
'author', 'taxonomy', 'concept', 'doc-emotion']
with open('C:\Users\Downloads\Python\name8.htm', 'rb') as html:
print(json.dumps(alchemy_language.combined(html=html.read(),
extract=combined_operations), indent=2))