0

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? I tried to use the following code and it is not working:

#html ='C:\Users\Downloads\Python\name8.htm'
Christian Will
  • 1,529
  • 3
  • 17
  • 25

1 Answers1

0

When using html you need to provide a string variable that contains the HTML code you want to analyze. In your code, you are trying using a file path as the content. Obviously, that's not HTML code.

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))
German Attanasio
  • 22,217
  • 7
  • 47
  • 63