代码拉取完成,页面将自动刷新
# coding=utf-8
import sys
import lxml
import cfscrape
from bs4 import BeautifulSoup
'''
中国内使用,需要翻墙(必须是 shadowrocks 全局模式,pac模式、自动模式等均无效)
'''
url = 'https://cn.torrentkitty.tv/search/'
# url = 'https://www.torrentkitty.tv/search/'
key = sys.argv[1]
scraper = cfscrape.create_scraper()
def create_parser(pageCount: int):
text = str(scraper.get(url + key + "/" + str(pageCount)).content, 'utf-8')
return BeautifulSoup(text,'lxml')
def parse_result(parser):
return parser.select('table#archiveResult > tr')
pageCount = 1
html_parser = create_parser(pageCount)
pages = html_parser.select('div#main > div.wrapper > div.pagination > a')
if len(pages) > 1:
pageCount = int(pages[-2]['href'])
print('pages', pageCount)
results = parse_result(html_parser)
for currentPage in range(2, pageCount + 1):
results += parse_result(create_parser(pageCount))
string = ''
for row in results:
names = row.select('td.name')
dates = row.select('td.date')
magnets = row.select('td.action > a:nth-child(2)')
if len(names) == 1 and len(dates) == 1 and len(magnets) == 1:
name = names[0].text
name = name.replace('[email protected]', '')
#print(name)
string += '[%s] %s\n%s\n\n'%(name, dates[0].text, magnets[0]['href'])
fileW = open(key + ".txt", "w")
fileW.write(string)
fileW.close()
print('done')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。