I ask you to tell, I want to collect the number of records from the wall in VK, with the help of vk api

rs = vk.method('wall.get', { 'owner_id': owner_id ,"type": "text", 'count':1 }) 

comes the following dictionary:

 [{u'attachments': [{u'photo': {u'access_key': u'21056d213f1c2d2d71', u'album_id': -7, u'date': 1501688727, u'height': 438, u'id': 456239202, u'owner_id': -142538016, u'photo_130': u'https://pp.userapi.com/c638329/v638329561/57ef4/SOC0CP8A0ds.jpg', u'photo_604': u'https://pp.userapi.com/c638329/v638329561/57ef5/8fc4dhhgwtI.jpg', u'photo_75': u'https://pp.userapi.com/c638329/v638329561/57ef3/enpGwhRr0_Y.jpg', u'post_id': 1224, u'text': u'', u'user_id': 100, u'width': 604}, u'type': u'photo'}],... type (rs) Out[73]: dict len (rs) Out[74]: 2 

I want to get only the number of posts, for example, only regular expressions come to mind, but for sure you can send a request to get just what I need. Please help.

    2 answers 2

    Here is what you are looking for.

    In general, better look here for questions api. There are examples there)

    To get the post_id each post, try something like this:

     wall = tools.get_all('wall.get', 100, {'owner_id': 1}) for post in wall['items']: print(post['id']) 

    Here is a description of the work of wall.get there you can see how the data is obtained and so on.

    • I get a normal response, it's just in the dictionary and I don't know how to get only the post_id, without resorting to re. This is the crux of the question, what you propose is the same. Well, then I want to get comments on the records and do not know how to parse them from this dictionary - egorkh
    • Read what you wrote, sometimes it is difficult to understand) - koshachok
    • Sorry from the phone - egorkh
    • I get a normal answer, it's just that it is in the dictionary with a bunch of fields, for example, I need only the text of the comment to the post, I can only bring the sheet inside the dictionary to a line and draw a comment with a regular expression, but it is crooked and long. How to properly send a request to get only comments to the post, for example. - egorkh
    • If anything, then I added the answer - koshachok

    You have inserted only a small part of the incoming request, and I do not fully understand why it is so distorted. Use the same wall.get , in the first response->count array there will be the number of entries. You can use the VK library for Python . There the necessary methods are immediately there.

    Link to the documentation with an example of work: here