Avatar ·

How to get user comments left in a particular community in VK

📁 method, Advanced Python Topics, example, requests, AI

How to get all the comments of a particular user left on the wall under posts in a particular community in VK?

I examined all the methods that exist in the VK API and have not yet found a way to complete this task.

The source data in this task is given the ID of the community.

Here is an example I tried to implement:


for i in range(200):
    url = ""https://api.vk.com/method/wall.get?owner_id=%s&offset=%s&count=1""%(self.text1.toplaintext(), i)
    response = requests.get(url).text
    parsed_string = json.loads(response)
    url1 = ""https://api.vk.com/method/wall.getComments?owner_id=%s&post_id=%s&count=100""%(self.text1.toplaintext(), parsed_string["response"]["items"][0]["id"])
    response1 = requests.get(url1).text
    parsed_string1 = json.loads(response1)
    for j in parsed_string1["response"]["items"]:
        if j["from_id"] == user_id:
            print(j["text"])