简体中文 / [English]


QQ Zone Crawler

 

This article is currently an experimental machine translation and may contain errors. If anything is unclear, please refer to the original Chinese version. I am continuously working to improve the translation.

I’m running out of ideas for my QQ nickname again lol.

So I thought—why not write a crawler to collect all QQ usernames and filter through them? Who knows, maybe I could even use TensorFlow to pick the perfect one.

Here’s the code snippet.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import requests
import json
import time
from util.RemoveCallback import remove_callback


def get_username_and_pic(uid, retry=3):

while True:
try:
res = requests.get("https://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg", verify=False, params={
"uins": uid
}, timeout=1)
break
except Exception as e:
retry -= 1
time.sleep(1)
if retry <= 0:
raise e

try:
res = json.loads(remove_callback(res.content.decode("gbk")))
except Exception as e:
print(e)
try:
res = json.loads(remove_callback(res.content.decode("utf-8")))
except Exception as e2:
print(e2)

name = res[str(uid)][6]
pic = res[str(uid)][0]
if name.replace(' ', '') != '':
return name, pic
else:
raise Exception("Failed to get name: RAW: " + str(res))

This article is licensed under the CC BY-NC-SA 4.0 license.

Author: lyc8503, Article link: https://blog.lyc8503.net/en/post/qzone-name-crawler/
If this article was helpful or interesting to you, consider buy me a coffee¬_¬
Feel free to comment in English below o/