From 3a31df3c0bcf25bdd39ce17b26b4ea21c71df0b6 Mon Sep 17 00:00:00 2001 From: sftang Date: Fri, 16 Sep 2022 17:56:19 +0800 Subject: [PATCH] u --- apps/common/sites_user.py | 278 ++++++++++++++++++-------------------- apps/common/utils.py | 18 +-- 2 files changed, 142 insertions(+), 154 deletions(-) diff --git a/apps/common/sites_user.py b/apps/common/sites_user.py index 6bb448e..4288868 100644 --- a/apps/common/sites_user.py +++ b/apps/common/sites_user.py @@ -107,164 +107,152 @@ def general(site_name, site_name_cn, site_url, site_cookie): #需要安装pip install lxml soup = BeautifulSoup(response.text, "lxml") - tables = soup.findAll('table', {'id':'info_block'}) - #print(tables) - if len(tables) != 0: + href = soup.find_all(href=re.compile("userdetails.php"), limit=1) + + #print(ul) + if len(href) != 0: - #span获取有2个,一个为用户信息,一个为信箱信息 - info = tables[0].findAll('span', {'class':'medium'}) - if info == []: - #获取只有1个 - info = tables[0].findAll('span', {'class':'nowrap'}) - user_info = info[0] - else: - user_info = info[0] - - #print(user_info) - #print("-------------") #用户详情链接 - user_info_link = user_info.a.attrs['href'] + user_info_link = href[0].attrs['href'] + #print(user_info_link) + #获取用户ID user_id = parseUrl(user_info_link)['query'].get('id',[])[0] - #用户名 - user_name = user_info.a.get_text() - #个人页无分享率的情况 - try: - #分享率 - ratio = user_info.find('font',{'class':'color_ratio'}).nextSibling.get_text() - data['ratio'] = ratio - except: - data['ratio'] = '0' - - #print("user_info_link--->",user_info_link) - #print("user_id--->",user_id) - #print("user_name--->",user_name) + data['user_id'] = user_id - data['user_name'] = user_name - if user_id == []: - data['msg'] = "格式错误" - return False, data - + userdetails_url = site_url + "/userdetails.php?id=%s" % user_id response = session.get(userdetails_url, headers=headers, timeout=10) - + #print(response.text) soup = BeautifulSoup(response.text, "lxml") - tables = soup.findAll('table', {'class':'main'}, limit=2) - if len(tables) == 2: - user_table = tables[1]#.find('table') + td = soup.findAll('td', string="用户名", limit=1) + if len(td) != 0: + user_name = td[0].nextSibling.get_text() else: - user_table = [] - - if user_table != []: - #print(user_table) + user_name = href[0].get_text() + if len(user_name) == 0: + td = soup.findAll('span', {'class':'nowrap'}, limit=1) + user_name = td[0].get_text() + data['user_name'] = user_name + + td = soup.findAll('td', string="加入日期", limit=1) + create_time = re.sub("\(.*\)",'', td[0].nextSibling.get_text().strip()) + data['create_time'] = create_time + + td = soup.findAll('td', string=["等级","等級"], limit=1) + level = re.sub("\(.*\)",'',td[0].nextSibling.get_text().strip()) + if level == "": + level = re.sub("\(.*\)",'',td[0].nextSibling.img.attrs['title']) + data['level'] = level + + td = soup.findAll('td', string=["邀请","邀請","剩余邀请量"], limit=1) + #删除非数字字符(获取字符串的整数) \D:表示非数字 + num = re.sub(r'\D+', '', td[0].nextSibling.get_text()) + if RepresentsInt(num): + data['invite'] = num + else: + data['invite'] = 0 + + td = soup.findAll('td', string="做种积分", limit=1) + try: + score = re.sub("\(.*\)",'', td[0].nextSibling.get_text()) + score = re.sub("\[.*\]",'', score) + except: + #无做种积分 + score = '0' + data['score'] = score.strip() + + td = soup.findAll('td', string="核心数据", limit=1) + if len(td) != 0: + #pttime + ratio = td[0].nextSibling.font.get_text() + data['ratio'] = ratio + #分隔4个连续空格['', '上传量: 21.367TB\n ', '下载量: 5.072TB', '魔力值: 6469.8'] + d =td[0].nextSibling.font.nextSibling.get_text().split(u'\xa0\xa0\xa0\xa0') + upload = d[1].split(':')[-1].replace('\\n','').strip() + data['upload'] = upload + download = d[2].split(':')[-1].strip() + data['download'] = download + bonus = d[3].split(':')[-1].strip() + data['bonus'] = bonus + + else: + #常规 + td = soup.findAll('td', string=["奶糖","魔力值"], limit=1) + bonus = td[0].nextSibling.get_text() + data['bonus'] = bonus - for index, tr in enumerate(user_table.find_all('tr')): - - if index == 0: - continue - - #由于获取td后 标题内存在一个table,实际完整的一个是15个td,标题后面2个td废弃 - tds = tr.find_all('td') - #print(tds) - #if '用户ID' in tds[0].get_text(): - #data['user_id'] = tds[1].get_text() - data_key = tds[0].get_text().strip() - data_value = tds[1].get_text().strip() - #if ('邀请' in tds[0].get_text() and '邀请人' not in tds[0].get_text()) or ('邀請' in tds[0].get_text() and '邀請人' not in tds[0].get_text()): - #if RepresentsInt(tds[1].get_text()): - #data['invite'] = tds[1].get_text() - #else: - #data['invite'] = 0 - if '邀请' == data_key or '邀請' == data_key or '剩余邀请量' == data_key : - #print(data_value) - #删除非数字字符(获取字符串的整数) \D:表示非数字 - num = re.sub(r'\D+', '', data_value) - if RepresentsInt(num): - data['invite'] = num - else: - data['invite'] = 0 - - #data['invite'] = data_value - - #if '加入日期' in tds[0].get_text(): - ##替换括号和括号的内容为空 - #data['create_time'] = re.sub("\(.*\)",'',tds[1].get_text()) - if '加入日期' == data_key: - data['create_time'] = re.sub("\(.*\)",'', data_value) - - if '分享率' in tds[0].get_text(): - data['ratio'] = tds[0].font.get_text() - - if ('上传量' in tds[0].get_text() and '实际' not in tds[0].get_text()) or ('上傳量' in tds[0].get_text() and '實際' not in tds[0].get_text()): - data['upload'] = re.sub("\(.*\)",'',tds[0].get_text().split(':')[-1]) - data['download'] = re.sub("\(.*\)",'',tds[1].get_text().split(':')[-1]) - - #pttime - if '核心数据' == data_key: - data['ratio'] = tds[1].font.get_text() - #分隔4个连续空格['', '上传量: 21.367TB\n ', '下载量: 5.072TB', '魔力值: 6469.8'] - d =tds[1].font.nextSibling.get_text().split(u'\xa0\xa0\xa0\xa0') - data['upload'] = d[1].split(':')[-1].replace('\\n','').strip() - data['download'] = d[2].split(':')[-1].strip() - data['bonus'] = d[3].split(':')[-1].strip() - - if '等级' in tds[0].get_text() or '等級' in tds[0].get_text(): - data['level'] = re.sub("\(.*\)",'',tds[1].img.attrs['title']) - - #if '魔力值' in tds[0].get_text(): - #data['bonus'] = tds[1].get_text() - - if '魔力值' == data_key: - data['bonus'] = data_value - - if '做种积分' in tds[0].get_text(): - data['score'] = tds[1].get_text() - - if '发布种子' in tds[0].get_text() or '發布種子' in tds[0].get_text(): - if '个种子' in tds[1].get_text(): - #页面直接包含数据 - data['published_seed_num'] = tds[1].a.nextSibling.get_text().split(',')[0].replace('(','').replace('个种子','') - else: - url = getSiteUrl(site_url) + "/getusertorrentlistajax.php?userid=%s&type=uploaded" % data['user_id'] - response = session.get(url, headers=headers, timeout=10) - soup = BeautifulSoup(response.text, "lxml") - published_seed_num= soup.find('b') - if published_seed_num != None: - data['published_seed_num'] = published_seed_num.get_text() - else: - data['published_seed_num'] = 0 - - if '当前做种' in tds[0].get_text() or '目前做種' in tds[0].get_text(): - if '个种子' in tds[1].get_text(): - data['seed_num'] = tds[1].a.nextSibling.get_text().split(',')[0].replace('(','').replace('个种子','') - data['totle_seed_size'] = tds[1].a.nextSibling.get_text().split(',')[-1].replace('(','').replace('共计','') - else: - url = getSiteUrl(site_url) + "/getusertorrentlistajax.php?userid=%s&type=seeding" % data['user_id'] - response = session.get(url, headers=headers, timeout=10) - soup = BeautifulSoup(response.text, "lxml") - seed_num= soup.find('b') - if seed_num != None: - data['seed_num'] = seed_num.get_text() - data['totle_seed_size'] = seed_num.nextSibling.get_text().split(':')[-1] - #pttime - if '记录' in data['totle_seed_size']: - url = site_url + "/getusertorrentlist.php?userid=%s&type=seeding" % data['user_id'] - response = session.get(url, headers=headers, timeout=10) - soup = BeautifulSoup(response.text, "lxml") - tds = soup.findAll('td',{'id':'outer'}, limit=2) - #print(tds) - span = tds[1].find_all('span') - #print(span[1].get_text()) - data['totle_seed_size'] = span[2].get_text().split(':')[-1].replace(u'\xa0','') - else: - data['seed_num'] = 0 - data['totle_seed_size'] = 0 - return True, data + td = soup.findAll('td', string=["上传量","上傳量"], limit=1) + try: + upload = td[0].nextSibling.get_text() + except: + td = soup.findAll('strong', string=["上传量","上傳量"], limit=1) + upload = re.sub("\(.*\)",'', td[0].nextSibling.get_text().split(':')[-1]) + data['upload'] = upload.strip() + + td = soup.findAll('td', string=["下载量","下載量"], limit=1) + try: + download = td[0].nextSibling.get_text() + except: + td = soup.findAll('strong', string=["下载量","下載量"], limit=1) + download = re.sub("\(.*\)",'', td[0].nextSibling.get_text().split(':')[-1]) + data['download'] = download.strip() + + td = soup.findAll('td', string="分享率", limit=1) + if len(td) != 0: + ratio = td[0].nextSibling.get_text() + else: + td = soup.findAll('strong', string="分享率", limit=1) + if len(td) != 0: + ratio = td[0].nextSibling.nextSibling.get_text() + else: + td = soup.findAll('font', {'class':'color_ratio'}, limit=1) + ratio = td[0].nextSibling.get_text() + + data['ratio'] = ratio.strip() + + td = soup.findAll('td', string=["发布种子","發布種子"], limit=1) + s = td[0].nextSibling.get_text() + if '个种子' in s or '记录' in s: + #页面直接包含数据 + if '察看' in s: + data['published_seed_num'] = s.split(',')[0].split('(')[-1].replace('个种子','') + else: + data['published_seed_num'] = re.sub(r'\D+', '', s) else: - data['msg'] = "格式错误" - return False, data + url = site_url + "/getusertorrentlistajax.php?userid=%s&type=uploaded" % data['user_id'] + response = session.get(url, headers=headers, timeout=10) + soup1 = BeautifulSoup(response.text, "lxml") + published_seed_num= soup1.find('b') + if published_seed_num != None: + data['published_seed_num'] = published_seed_num.get_text() + else: + data['published_seed_num'] = 0 + + td = soup.findAll('td', string=["当前做种","目前做種"], limit=1) + s = td[0].nextSibling.get_text() + if '个种子' in s or '记录' in s: + if '察看' in s: + data['seed_num'] = s.split(',')[0].split('(')[-1].replace('个种子','') + data['totle_seed_size'] = s.split(',')[-1].replace(')','').replace('共计','') + else: + data['seed_num'] = re.sub(r'\D+', '', s) + data['totle_seed_size'] = 0 + + else: + url = site_url + "/getusertorrentlistajax.php?userid=%s&type=seeding" % data['user_id'] + response = session.get(url, headers=headers, timeout=10) + soup1 = BeautifulSoup(response.text, "lxml") + seed_num= soup1.find('b') + if seed_num != None: + data['seed_num'] = seed_num.get_text() + data['totle_seed_size'] = seed_num.nextSibling.get_text().split(':')[-1] + else: + data['seed_num'] = 0 + data['totle_seed_size'] = 0 + return True, data else: data['msg'] = "格式错误" return False, data diff --git a/apps/common/utils.py b/apps/common/utils.py index b5ef139..b540e76 100644 --- a/apps/common/utils.py +++ b/apps/common/utils.py @@ -867,12 +867,12 @@ def Unicode(): val = random.randint(0x4e00, 0x9fbf) return chr(val) -def GBK2312(): - """ - 随机产生汉字 - """ - head = random.randint(0xb0, 0xf7) - body = random.randint(0xa1, 0xfe) - val = f'{head:x} {body:x}' - str = bytes.fromhex(val).decode('gb2312') - return str \ No newline at end of file +#def GBK2312(): + #""" + #随机产生汉字 + #""" + #head = random.randint(0xb0, 0xf7) + #body = random.randint(0xa1, 0xfe) + #val = f'{head:x} {body:x}' + #str = bytes.fromhex(val).decode('gb2312') + #return str \ No newline at end of file