the goal with this script Is to scrape comments from posts on Instagram. The expected results Is the name, comment and profile link of the user that commented. But what I get Is this error to be precise, UnicodeEncodeError: 'charmap' codec can't encode characters in position 60-61: character maps to <undefined>
.
Currently I'm using this command to pull the comment text which Is the only one causing issues.
comment = browser.find_element_by_xpath('//*[@id="react-root"]/section/main/div/div[1]/article/div[3]/div[1]/ul/ul[{}]/div/li/div/div[1]/div[2]/span'.format(i)).get_attribute('textContent')
With that one It gives me an error, but If I replace the .format
command and the {}
with the number 1
It works. But I can't do that since It won't get the rest of the comments. It looks like this instead.
comment = browser.find_element_by_xpath('//*[@id="react-root"]/section/main/div/div[1]/article/div[3]/div[1]/ul/ul[1]/div/li/div/div[1]/div[2]/span').get_attribute('textContent')
That works and does not raise an error. I'm aware of the fact that this Is loosely discribed, I just don't know what more to write. If you need more information just leave a comment and I'll do my best to provide It. Thanks.