avsox.py: 元数据新增剧情介绍。优化:减少etree.fromstring高开销调用次数
This commit is contained in:
@@ -5,12 +5,11 @@ from lxml import etree
|
|||||||
import json
|
import json
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from ADC_function import *
|
from ADC_function import *
|
||||||
# import sys
|
from WebCrawler.storyline import getStoryline
|
||||||
# import io
|
# import io
|
||||||
# sys.stdout = io.TextIOWrapper(sys.stdout.buffer, errors = 'replace', line_buffering = True)
|
# sys.stdout = io.TextIOWrapper(sys.stdout.buffer, errors = 'replace', line_buffering = True)
|
||||||
|
|
||||||
def getActorPhoto(htmlcode): #//*[@id="star_qdt"]/li/a/img
|
def getActorPhoto(soup):
|
||||||
soup = BeautifulSoup(htmlcode, 'lxml')
|
|
||||||
a = soup.find_all(attrs={'class': 'avatar-box'})
|
a = soup.find_all(attrs={'class': 'avatar-box'})
|
||||||
d = {}
|
d = {}
|
||||||
for i in a:
|
for i in a:
|
||||||
@@ -19,34 +18,28 @@ def getActorPhoto(htmlcode): #//*[@id="star_qdt"]/li/a/img
|
|||||||
p2 = {t: l}
|
p2 = {t: l}
|
||||||
d.update(p2)
|
d.update(p2)
|
||||||
return d
|
return d
|
||||||
def getTitle(a):
|
def getTitle(html):
|
||||||
try:
|
try:
|
||||||
html = etree.fromstring(a, etree.HTMLParser())
|
|
||||||
result = str(html.xpath('/html/body/div[2]/h3/text()')).strip(" ['']") #[0]
|
result = str(html.xpath('/html/body/div[2]/h3/text()')).strip(" ['']") #[0]
|
||||||
return result.replace('/', '')
|
return result.replace('/', '')
|
||||||
except:
|
except:
|
||||||
return ''
|
return ''
|
||||||
def getActor(a): #//*[@id="center_column"]/div[2]/div[1]/div/table/tbody/tr[1]/td/text()
|
def getActor(soup):
|
||||||
soup = BeautifulSoup(a, 'lxml')
|
|
||||||
a = soup.find_all(attrs={'class': 'avatar-box'})
|
a = soup.find_all(attrs={'class': 'avatar-box'})
|
||||||
d = []
|
d = []
|
||||||
for i in a:
|
for i in a:
|
||||||
d.append(i.span.get_text())
|
d.append(i.span.get_text())
|
||||||
return d
|
return d
|
||||||
def getStudio(a):
|
def getStudio(html):
|
||||||
html = etree.fromstring(a, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
|
|
||||||
result1 = str(html.xpath('//p[contains(text(),"制作商: ")]/following-sibling::p[1]/a/text()')).strip(" ['']").replace("', '",' ')
|
result1 = str(html.xpath('//p[contains(text(),"制作商: ")]/following-sibling::p[1]/a/text()')).strip(" ['']").replace("', '",' ')
|
||||||
return result1
|
return result1
|
||||||
def getRuntime(a):
|
def getRuntime(html):
|
||||||
html = etree.fromstring(a, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
|
|
||||||
result1 = str(html.xpath('//span[contains(text(),"长度:")]/../text()')).strip(" ['分钟']")
|
result1 = str(html.xpath('//span[contains(text(),"长度:")]/../text()')).strip(" ['分钟']")
|
||||||
return result1
|
return result1
|
||||||
def getLabel(a):
|
def getLabel(html):
|
||||||
html = etree.fromstring(a, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
|
|
||||||
result1 = str(html.xpath('//p[contains(text(),"系列:")]/following-sibling::p[1]/a/text()')).strip(" ['']")
|
result1 = str(html.xpath('//p[contains(text(),"系列:")]/following-sibling::p[1]/a/text()')).strip(" ['']")
|
||||||
return result1
|
return result1
|
||||||
def getNum(a):
|
def getNum(html):
|
||||||
html = etree.fromstring(a, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
|
|
||||||
result1 = str(html.xpath('//span[contains(text(),"识别码:")]/../span[2]/text()')).strip(" ['']")
|
result1 = str(html.xpath('//span[contains(text(),"识别码:")]/../span[2]/text()')).strip(" ['']")
|
||||||
return result1
|
return result1
|
||||||
def getYear(release):
|
def getYear(release):
|
||||||
@@ -55,28 +48,23 @@ def getYear(release):
|
|||||||
return result
|
return result
|
||||||
except:
|
except:
|
||||||
return release
|
return release
|
||||||
def getRelease(a):
|
def getRelease(html):
|
||||||
html = etree.fromstring(a, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
|
|
||||||
result1 = str(html.xpath('//span[contains(text(),"发行时间:")]/../text()')).strip(" ['']")
|
result1 = str(html.xpath('//span[contains(text(),"发行时间:")]/../text()')).strip(" ['']")
|
||||||
return result1
|
return result1
|
||||||
def getCover(htmlcode):
|
def getCover(html):
|
||||||
html = etree.fromstring(htmlcode, etree.HTMLParser())
|
|
||||||
result = str(html.xpath('/html/body/div[2]/div[1]/div[1]/a/img/@src')).strip(" ['']")
|
result = str(html.xpath('/html/body/div[2]/div[1]/div[1]/a/img/@src')).strip(" ['']")
|
||||||
return result
|
return result
|
||||||
def getCover_small(htmlcode):
|
def getCover_small(html):
|
||||||
html = etree.fromstring(htmlcode, etree.HTMLParser())
|
|
||||||
result = str(html.xpath('//*[@id="waterfall"]/div/a/div[1]/img/@src')).strip(" ['']")
|
result = str(html.xpath('//*[@id="waterfall"]/div/a/div[1]/img/@src')).strip(" ['']")
|
||||||
return result
|
return result
|
||||||
def getTag(a): # 获取演员
|
def getTag(soup): # 获取演员
|
||||||
soup = BeautifulSoup(a, 'lxml')
|
|
||||||
a = soup.find_all(attrs={'class': 'genre'})
|
a = soup.find_all(attrs={'class': 'genre'})
|
||||||
d = []
|
d = []
|
||||||
for i in a:
|
for i in a:
|
||||||
d.append(i.get_text())
|
d.append(i.get_text())
|
||||||
return d
|
return d
|
||||||
def getSeries(htmlcode):
|
def getSeries(html):
|
||||||
try:
|
try:
|
||||||
html = etree.fromstring(htmlcode, etree.HTMLParser()) # //table/tr[1]/td[1]/text()
|
|
||||||
result1 = str(html.xpath('//span[contains(text(),"系列:")]/../span[2]/text()')).strip(" ['']")
|
result1 = str(html.xpath('//span[contains(text(),"系列:")]/../span[2]/text()')).strip(" ['']")
|
||||||
return result1
|
return result1
|
||||||
except:
|
except:
|
||||||
@@ -98,27 +86,30 @@ def main(number):
|
|||||||
result1 = str(html.xpath('//*[@id="waterfall"]/div/a/@href')).strip(" ['']")
|
result1 = str(html.xpath('//*[@id="waterfall"]/div/a/@href')).strip(" ['']")
|
||||||
web = get_html("https:" + result1)
|
web = get_html("https:" + result1)
|
||||||
soup = BeautifulSoup(web, 'lxml')
|
soup = BeautifulSoup(web, 'lxml')
|
||||||
|
web = etree.fromstring(web, etree.HTMLParser())
|
||||||
info = str(soup.find(attrs={'class': 'row movie'}))
|
info = str(soup.find(attrs={'class': 'row movie'}))
|
||||||
|
info = etree.fromstring(info, etree.HTMLParser())
|
||||||
try:
|
try:
|
||||||
new_number = getNum(info)
|
new_number = getNum(info)
|
||||||
if new_number.upper() != number.upper():
|
if new_number.upper() != number.upper():
|
||||||
raise ValueError('number not found')
|
raise ValueError('number not found')
|
||||||
|
title = getTitle(web).strip(getNum(web))
|
||||||
dic = {
|
dic = {
|
||||||
'actor': getActor(web),
|
'actor': getActor(soup),
|
||||||
'title': getTitle(web).strip(getNum(web)),
|
'title': title,
|
||||||
'studio': getStudio(info),
|
'studio': getStudio(info),
|
||||||
'outline': '', #
|
'outline': getStoryline(number, title),
|
||||||
'runtime': getRuntime(info),
|
'runtime': getRuntime(info),
|
||||||
'director': '', #
|
'director': '', #
|
||||||
'release': getRelease(info),
|
'release': getRelease(info),
|
||||||
'number': new_number,
|
'number': new_number,
|
||||||
'cover': getCover(web),
|
'cover': getCover(web),
|
||||||
'cover_small': getCover_small(a),
|
'cover_small': getCover_small(html),
|
||||||
'imagecut': 3,
|
'imagecut': 3,
|
||||||
'tag': getTag(web),
|
'tag': getTag(soup),
|
||||||
'label': getLabel(info),
|
'label': getLabel(info),
|
||||||
'year': getYear(getRelease(info)), # str(re.search('\d{4}',getRelease(a)).group()),
|
'year': getYear(getRelease(info)), # str(re.search('\d{4}',getRelease(a)).group()),
|
||||||
'actor_photo': getActorPhoto(web),
|
'actor_photo': getActorPhoto(soup),
|
||||||
'website': "https:" + result1,
|
'website': "https:" + result1,
|
||||||
'source': 'avsox.py',
|
'source': 'avsox.py',
|
||||||
'series': getSeries(info),
|
'series': getSeries(info),
|
||||||
|
|||||||
Reference in New Issue
Block a user