47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
import requests
|
||
import time
|
||
|
||
base_url = "https://invites.fun/api/users?include&sort&page%5Boffset%5D="
|
||
|
||
keyword = "catchthefish-fishes"
|
||
total_count = 0
|
||
usernames = []
|
||
|
||
cookies = {
|
||
"flarum_remember": "izvHQwoKddgwYWC9e1dFLfcADCOjMnhl2xIEk2BP",
|
||
"flarum_session": "sGfH8SLqRdmVU4b9p9IIcIu2LEmL6vt0BtkR4GS9"
|
||
}
|
||
|
||
headers = {
|
||
"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36'
|
||
}
|
||
|
||
for offset in range(0, 2001, 20):
|
||
url = base_url + str(offset)
|
||
response = requests.get(url, cookies=cookies, headers=headers)
|
||
|
||
if response.status_code == 200:
|
||
count = response.text.count(keyword)
|
||
total_count += count
|
||
|
||
if count > 0:
|
||
index = response.text.find(keyword)
|
||
start_index = response.text.rfind('"username"', 0, index) + 12
|
||
end_index = response.text.find('"', start_index)
|
||
username = response.text[start_index:end_index]
|
||
usernames.append(username)
|
||
print("第一个出现的用户名(username):", username)
|
||
|
||
print("当前 offset 值:", offset)
|
||
print("关键词“catchthefish-fishes”出现的次数:", count)
|
||
|
||
count = 0 # 清零关键词出现的次数
|
||
|
||
time.sleep(1) # 延时1秒
|
||
|
||
print("最终关键词“catchthefish-fishes”出现的次数:", total_count)
|
||
|
||
print("所有获取到的用户名(username):")
|
||
for username in usernames:
|
||
print(username)
|