本文作者: 峡州仙士
原文链接: https://cjh0613.github.io/blog/20200520getQQmembers.html
版权声明: 本网站(峡州仙士之页)所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
序
发现上半年压了一堆实用代码,想了一下,还是开源吧。这个就先发布了。
{% note danger no-icon %}
警告
请合理使用此代码,严禁用于广告、信息售卖等反人类用途
使用时请注意不要超负荷访问腾讯服务器
{% endnote %}
最新代码已传至G站Github:https://github.com/cjh0613/getQQmembers
(欢迎各位改良并Pull Request)
主要使用selenium+chrome,加了Tkinter的简单GUI,代码比较简单,就不细说了,请自行品味:
成品:http://d0.ananas.chaoxing.com/download/7694e31d48eedb7b57e5aeefadf67134?fn=qq%E5%A4%87%E4%BB%BD
获取qq好友列表
这个是从QQ充值获取的,可得"原始数据",“分组”,“显示名”,“QQ号”:
- 会自动打开QQ充值,请网页登陆
- Q币充值,打开充值界面
- 充值账号,点更换,打开列表
- 点击窗口的’已登陆并打开充值界面,且点开列表’按钮
import selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import tkinter as tk
from tkinter.filedialog import asksaveasfilename
from bs4 import BeautifulSoup
import lxml
import openpyxl
from openpyxl import Workbook
def callback():
driver.switch_to_frame('webpay-iframe')
iframe =driver.find_element_by_xpath('//*[@id="midas-webpay-main-1450000186"]/div[2]/div[1]/iframe')
driver.switch_to_frame(iframe)
html=driver.page_source
soup=BeautifulSoup(html,"lxml")
a=soup.find_all(attrs={
'class':'icon-friend-s'})
wb = Workbook()
ws = wb.active
ws.append(["原始数据","分组","显示名","QQ号"])
for i in a:
if i.next_sibling !=' {
{el.name}}({
{el.qq}})':
#re,qq匹配:
#pattern = re.compile(r'[1-9][0-9]{4,}')
#re,括号匹配:
#pattern = re.compile(r'(?<=\().*?(?=\))')
#m = pattern.search(i.next_sibling)
k