fc2 php,fc2fans_club.py

import re

from lxml import etree#need install

import json

import ADC_function

# import sys

# import io

# sys.stdout = io.TextIOWrapper(sys.stdout.buffer, errors = 'replace', line_buffering = True)

def getTitle(htmlcode): #获取厂商

#print(htmlcode)

html = etree.fromstring(htmlcode,etree.HTMLParser())

result = str(html.xpath('/html/body/div[2]/div/div[1]/h3/text()')).strip(" ['']")

result2 = str(re.sub('\D{2}2-\d+','',result)).replace(' ','',1)

#print(result2)

return result2

def getActor(htmlcode):

try:

html = etree.fromstring(htmlcode, etree.HTMLParser())

result = str(html.xpath('/html/body/div[2]/div/div[1]/h5[5]/a/text()')).strip(" ['']")

return result

except:

return ''

def getStudio(htmlcode): #获取厂商

html = etree.fromstring(htmlcode,etree.HTMLParser())

result = str(html.xpath('/html/body/div[2]/div/div[1]/h5[3]/a[1]/text()')).strip(" ['']")

return result

def getNum(htmlcode): #获取番号

html = etree.fromstring(htmlcode, etree.HTMLParser())

result = str(html.xpath('/html/body/div[5]/div[1]/div[2]/p[1]/span[2]/text()')).strip(" ['']")

#print(result)

return result

def getRelease(htmlcode2): #

#a=ADC_function.get_html('http://adult.contents.fc2.com/article_search.php?id='+str(number).lstrip("FC2-").lstrip("fc2-").lstrip("fc2_").lstrip("fc2-")+'&utm_source=aff_php&utm_medium=source_code&utm_campaign=from_aff_php')

html=etree.fromstring(htmlcode2,etree.HTMLParser())

result = str(html.xpath('//*[@id="container"]/div[1]/div/article/section[1]/div/div[2]/dl/dd[4]/text()')).strip(" ['']")

return result

def getCover(htmlcode,number,htmlcode2): #获取厂商 #

#a = ADC_function.get_html('http://adult.contents.fc2.com/article_search.php?id=' + str(number).lstrip("FC2-").lstrip("fc2-").lstrip("fc2_").lstrip("fc2-") + '&utm_source=aff_php&utm_medium=source_code&utm_campaign=from_aff_php')

html = etree.fromstring(htmlcode2, etree.HTMLParser())

result = str(html.xpath('//*[@id="container"]/div[1]/div/article/section[1]/div/div[1]/a/img/@src')).strip(" ['']")

if result == '':

html = etree.fromstring(htmlcode, etree.HTMLParser())

result2 = str(html.xpath('//*[@id="slider"]/ul[1]/li[1]/img/@src')).strip(" ['']")

return 'https://fc2club.com' + result2

return 'http:' + result

def getOutline(htmlcode2): #获取番号 #

html = etree.fromstring(htmlcode2, etree.HTMLParser())

result = str(html.xpath('/html/body/div[1]/div[2]/div[2]/div[1]/div/article/section[4]/p/text()')).strip(" ['']").replace("\\n",'',10000).replace("'",'',10000).replace(', ,','').strip(' ').replace('。,',',')

return result

def getTag(htmlcode): #获取番号

html = etree.fromstring(htmlcode, etree.HTMLParser())

result = str(html.xpath('/html/body/div[2]/div/div[1]/h5[4]/a/text()'))

return result.strip(" ['']").replace("'",'').replace(' ','')

def getYear(release):

try:

result = re.search('\d{4}',release).group()

return result

except:

return ''

def getTitle_fc2com(htmlcode): #获取厂商

html = etree.fromstring(htmlcode,etree.HTMLParser())

result = html.xpath('//*[@id="top"]/div[1]/section[1]/div/section/div[2]/h3/text()')[0]

return result

def getActor_fc2com(htmlcode):

try:

html = etree.fromstring(htmlcode, etree.HTMLParser())

result = html.xpath('//*[@id="top"]/div[1]/section[1]/div/section/div[2]/ul/li[3]/a/text()')[0]

return result

except:

return ''

def getStudio_fc2com(htmlcode): #获取厂商

try:

html = etree.fromstring(htmlcode, etree.HTMLParser())

result = str(html.xpath('//*[@id="top"]/div[1]/section[1]/div/section/div[2]/ul/li[3]/a/text()')).strip(" ['']")

return result

except:

return ''

def getNum_fc2com(htmlcode): #获取番号

html = etree.fromstring(htmlcode, etree.HTMLParser())

result = str(html.xpath('/html/body/div[5]/div[1]/div[2]/p[1]/span[2]/text()')).strip(" ['']")

return result

def getRelease_fc2com(htmlcode2): #

html=etree.fromstring(htmlcode2,etree.HTMLParser())

result = str(html.xpath('//*[@id="container"]/div[1]/div/article/section[1]/div/div[2]/dl/dd[4]/text()')).strip(" ['']")

return result

def getCover_fc2com(htmlcode2): #获取厂商 #

html = etree.fromstring(htmlcode2, etree.HTMLParser())

result = str(html.xpath('//*[@id="top"]/div[1]/section[1]/div/section/div[1]/span/img/@src')).strip(" ['']")

return 'http:' + result

def getOutline_fc2com(htmlcode2): #获取番号 #

html = etree.fromstring(htmlcode2, etree.HTMLParser())

result = str(html.xpath('/html/body/div/text()')).strip(" ['']").replace("\\n",'',10000).replace("'",'',10000).replace(', ,','').strip(' ').replace('。,',',')

return result

def getTag_fc2com(number): #获取番号

htmlcode = str(bytes(ADC_function.get_html('http://adult.contents.fc2.com/api/v4/article/'+number+'/tag?'),'utf-8').decode('unicode-escape'))

result = re.findall('"tag":"(.*?)"', htmlcode)

return result

def getYear_fc2com(release):

try:

result = re.search('\d{4}',release).group()

return result

except:

return ''

def main(number):

try:

number = number.replace('FC2-', '').replace('fc2-', '')

htmlcode2 = ADC_function.get_html('https://adult.contents.fc2.com/article/'+number+'/')

htmlcode = ADC_function.get_html('https://fc2club.com//html/FC2-' + number + '.html')

actor = getActor(htmlcode)

if getActor(htmlcode) == '':

actor = 'FC2系列'

dic = {

'title': getTitle(htmlcode),

'studio': getStudio(htmlcode),

'year': '',#str(re.search('\d{4}',getRelease(number)).group()),

'outline': '',#getOutline(htmlcode2),

'runtime': getYear(getRelease(htmlcode)),

'director': getStudio(htmlcode),

'actor': actor,

'release': getRelease(number),

'number': 'FC2-'+number,

'label': '',

'cover': getCover(htmlcode,number,htmlcode2),

'imagecut': 0,

'tag': getTag(htmlcode),

'actor_photo':'',

'website': 'https://fc2club.com//html/FC2-' + number + '.html',

'source':'https://fc2club.com//html/FC2-' + number + '.html',

}

if dic['title'] == '':

htmlcode2 = ADC_function.get_html('https://adult.contents.fc2.com/article/' + number + '/',cookies={'wei6H':'1'})

actor = getActor(htmlcode)

if getActor(htmlcode) == '':

actor = 'FC2系列'

dic = {

'title': getTitle_fc2com(htmlcode2),

'studio': getStudio_fc2com(htmlcode2),

'year': '', # str(re.search('\d{4}',getRelease(number)).group()),

'outline': getOutline_fc2com(htmlcode2),

'runtime': getYear_fc2com(getRelease(htmlcode2)),

'director': getStudio_fc2com(htmlcode2),

'actor': actor,

'release': getRelease_fc2com(number),

'number': 'FC2-' + number,

'cover': getCover_fc2com(htmlcode2),

'imagecut': 0,

'tag': getTag_fc2com(number),

'label': '',

'actor_photo': '',

'website': 'http://adult.contents.fc2.com/article/' + number + '/',

'source': 'http://adult.contents.fc2.com/article/' + number + '/',

}

except Exception as e:

# (TODO) better handle this

# print(e)

dic = {"title": ""}

js = json.dumps(dic, ensure_ascii=False, sort_keys=True, indent=4, separators=(',', ':'),)#.encode('UTF-8')

return js

#print(main('1252953'))

一键复制

编辑

Web IDE

原始数据

按行查看

历史

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段代码中包含了模型的微调(fine-tuning)部分。根据代码中的条件`args.fine_tune`,如果为`True`,则执行以下操作: 1. 修改模型的全连接层(fc): - `model.fc = nn.Linear(model.fc.in_features, args.classes_level2)`:将模型的全连接层修改为输出维度为`args.classes_level2`的线性层。这个操作可能是为了在微调时,将模型的输出层调整为新的分类任务。 2. 加载预训练模型权重: - `model.load_state_dict(...)`:从指定路径加载预训练模型的权重。`config.save_path`是保存模型权重的路径,`config.model_name`是模型的名称,`name`是根据`config.classify_type`生成的新名称,`5`是一个数字,可能表示预训练模型的版本号或其他标识符。这个操作可能是为了将预训练模型的权重加载到模型中,以便在微调过程中使用。 3. 冻结预训练模型的参数: - `for param in model.parameters(): param.requires_grad = False`:将模型中所有参数的梯度计算设置为不可求导,即冻结参数。这个操作可能是为了在微调过程中只更新新添加的全连接层的参数。 4. 修改模型的全连接层(fc)为新的分类任务: - `model.fc = nn.Linear(model.fc.in_features, config.num_classes)`:将模型的全连接层修改为输出维度为`config.num_classes`的线性层。这个操作可能是为了适应新的分类任务,将模型的输出层调整为正确的类别数。 5. 使用 Xavier 初始化方法和常数初始化方法对新的全连接层参数进行初始化: - `torch.nn.init.xavier_normal_(model.fc.weight.data)`:使用 Xavier 初始化方法对全连接层的权重进行初始化。 - `nn.init.constant_(model.fc.bias.data, 0)`:使用常数初始化方法将全连接层的偏置项初始化为零。 通过以上操作,可以实现对预训练模型的微调,将其适应新的分类任务。需要注意的是,这段代码中的具体逻辑和参数值可能根据实际情况有所变化,你可以根据实际的代码逻辑和配置参数来理解这段代码的具体作用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值