[英]IBM Bluemix - Watson Alchemy - How to refer to a local directory on my laptop
Currently, I am using the following code to do analysis for a website: 目前,我正在使用以下代码对网站进行分析:
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))
Can anyone tell me how to refer to a local directory where I am having my own html file for analysis? 谁能告诉我如何引用我自己的html文件进行分析的本地目录? I tried to use the following code and it is not working:
我尝试使用以下代码,但无法正常工作:
#html ='C:\Users\Downloads\Python\name8.htm'
When using html
you need to provide a string variable that contains the HTML code you want to analyze. 使用
html
您需要提供一个字符串变量,其中包含要分析的HTML代码。 In your code, you are trying using a file path as the content. 在您的代码中,您尝试使用文件路径作为内容。 Obviously, that's not HTML code.
显然,那不是HTML代码。
Try with: 尝试:
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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.