Answer the question
In order to leave comments, you need to log in
An error in the parser code for VK, am I doing something wrong?
Roughly speaking, it checks whether there is such a VK ID or not, for example:
durov - busy ID
Anna - Borrow ID
12 - Free ID Error 404 page not found
Roughly speaking, load the list into a column of 1000+ id and believe there is such an ID or not?
So that I could pick up a short, unoccupied letter ID Well, you understand me.
If there is a free ID from the list of my ID, then it writes to the file, if not, then it’s bad)
import requests
file = open('urls.txt', 'r')
not_found = open('not_found.txt', 'w')
found = open('found.txt', 'w')
for line in file:
id = line.split('\n')[0]
if id.isdigit():
text = requests.get('https://vk.com/id'+id).text
else:
text = requests.get('https://vk.com/'+id).text
if '<title>404 Not Found</title>' in text:
print('Not found: '+id)
not_found.write(id+'\n')
not_found.flush()
else:
print('Found: '+id)
found.write(id+'\n')
found.flush()
found.close()
not_found.close()
file.close()
Answer the question
In order to leave comments, you need to log in
You should pay attention to the py-vkontakte library , which allows you to work with the vk.com API.
def get_user_not_found(users):
for user in users:
try:
api.get_user(user)
except vk.error.VKError as err:
if '113' == err.code:
yield user
>>> ['asdf0aisdf', 'durov', 123]
>>> [user for user in get_user_not_found(users)]
['asdf0aisdf']
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question