0

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.

Mr Ikea
  • 41
  • 9
  • does this answer your question https://stackoverflow.com/questions/27092833/unicodeencodeerror-charmap-codec-cant-encode-characters ? – Yato Sep 05 '21 at 12:55
  • If you go on this post, https://www.instagram.com/reel/CS8Bzv7H78w/, open inspector mode and open the DOM. Then copy & paste in this 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', you should be directed to the top comment. That Is the text that I want to pull but It Is raising an error. – Mr Ikea Sep 05 '21 at 12:56
  • @Bakax It does actually, I'm no longer getting the error. Thanks bro. – Mr Ikea Sep 05 '21 at 12:58

0 Answers0