Issue
Good morning, I'm currently trying to download a certain field of an instagram post using Python selenium. Specifically, I'm trying to download the caption (description) of the picture (which, for example, in the picture below would be the section that starts with the text "Thanks @lolap ....." all the way down to the hashtags.
I tried the following code, however it appears that it isn't working (it throws an exception right away):
caption = driver.findElement(By.xpath("/html/body/div[3]/div[2]/div/article/div[2]/div[1]/ul/div/li/div/div/div[2]/span/text()")) #get all the caption text in a String
Thanks for your help.
Solution
Are you just trying to collect all the hashtags?
Try this:
hashtags = driver.find_elements_by_xpath("//a[@class='xil3i']")
for tag in hashtags:
print(tag.text)
Or, if you are looking for the picture description:
desc_text = driver.find_element_by_xpath("//span[@title='Edited']").text
print(desc_text)
Answered By - JD2775
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.