javbus.py: 优化提速

This commit is contained in:
lededev
2021-10-19 00:58:28 +08:00
parent 5da134986a
commit 249884a27e

View File

@@ -1,19 +1,18 @@
import sys import sys
sys.path.append('../') sys.path.append('../')
import re import re
from pyquery import PyQuery as pq#need install
from lxml import etree#need install from lxml import etree#need install
import json import json
from ADC_function import * from ADC_function import *
from WebCrawler.storyline import getStoryline from WebCrawler.storyline import getStoryline
import inspect import inspect
def getActorPhoto(doc): #//*[@id="star_qdt"]/li/a/img def getActorPhoto(html):
actors = doc('div.star-name a').items() actors = html.xpath('//div[@class="star-name"]/a')
d={} d={}
for i in actors: for i in actors:
url=i.attr.href url=i.attrib['href']
t=i.attr.title t=i.attrib['title']
html = etree.fromstring(get_html(url), etree.HTMLParser()) html = etree.fromstring(get_html(url), etree.HTMLParser())
p=urljoin("https://www.javbus.com", p=urljoin("https://www.javbus.com",
str(html.xpath('//*[@id="waterfall"]/div[1]/div/div[1]/img/@src')).strip(" ['']")) str(html.xpath('//*[@id="waterfall"]/div[1]/div/div[1]/img/@src')).strip(" ['']"))
@@ -33,20 +32,20 @@ def getStudio(html): #获取厂商
def getYear(html): #获取年份 def getYear(html): #获取年份
result = str(html.xpath('/html/body/div[5]/div[1]/div[2]/p[2]/text()')).strip(" ['']").strip() result = str(html.xpath('/html/body/div[5]/div[1]/div[2]/p[2]/text()')).strip(" ['']").strip()
return result[:4] if len(result)>=len('2000-01-01') else '' return result[:4] if len(result)>=len('2000-01-01') else ''
def getCover(doc): #获取封面链接 def getCover(html): #获取封面链接
image = doc('a.bigImage') image = str(html.xpath('//a[@class="bigImage"]/@href')[0])
return urljoin("https://www.javbus.com", image.attr('href')) return urljoin("https://www.javbus.com", image)
def getRelease(html): #获取出版日期 def getRelease(html): #获取出版日期
result = str(html.xpath('/html/body/div[5]/div[1]/div[2]/p[2]/text()')).strip(" ['']") result = str(html.xpath('/html/body/div[5]/div[1]/div[2]/p[2]/text()')).strip(" ['']")
return result return result
def getRuntime(html): #获取分钟 已修改 def getRuntime(html): #获取分钟 已修改
result = str(html.xpath('/html/body/div[5]/div[1]/div[2]/p[3]/text()')).strip(" ['']分鐘") result = str(html.xpath('/html/body/div[5]/div[1]/div[2]/p[3]/text()')).strip(" ['']分鐘")
return result return result
def getActor(doc): #获取女优 def getActor(html): #获取女优
b=[] b=[]
actors = doc('div.star-name a').items() actors = html.xpath('//div[@class="star-name"]/a')
for i in actors: for i in actors:
b.append(i.attr.title) b.append(i.attrib['title'])
return b return b
def getNum(html): #获取番号 def getNum(html): #获取番号
kwdlist = html.xpath('/html/head/meta[@name="keywords"]/@content')[0].split(',') kwdlist = html.xpath('/html/head/meta[@name="keywords"]/@content')[0].split(',')
@@ -99,7 +98,6 @@ def main_uncensored(number):
htmlcode = get_html('https://www.javbus.com/ja/' + number) htmlcode = get_html('https://www.javbus.com/ja/' + number)
if "<title>404 Page Not Found" in htmlcode: if "<title>404 Page Not Found" in htmlcode:
raise Exception('404 page not found') raise Exception('404 page not found')
doc = pq(htmlcode)
lx = etree.fromstring(htmlcode, etree.HTMLParser()) lx = etree.fromstring(htmlcode, etree.HTMLParser())
title = getTitle(lx) title = getTitle(lx)
dic = { dic = {
@@ -109,10 +107,10 @@ def main_uncensored(number):
'outline': getOutline(number, title), 'outline': getOutline(number, title),
'runtime': getRuntime(lx), 'runtime': getRuntime(lx),
'director': getDirectorJa(lx), 'director': getDirectorJa(lx),
'actor': getActor(doc), 'actor': getActor(lx),
'release': getRelease(lx), 'release': getRelease(lx),
'number': getNum(lx), 'number': getNum(lx),
'cover': getCover(doc), 'cover': getCover(lx),
'tag': getTag(lx), 'tag': getTag(lx),
'extrafanart': getExtrafanart(htmlcode), 'extrafanart': getExtrafanart(htmlcode),
'label': getSeriseJa(lx), 'label': getSeriseJa(lx),
@@ -135,7 +133,6 @@ def main(number):
htmlcode = get_html('https://www.javbus.com/' + number) htmlcode = get_html('https://www.javbus.com/' + number)
if "<title>404 Page Not Found" in htmlcode: if "<title>404 Page Not Found" in htmlcode:
raise Exception('404 page not found') raise Exception('404 page not found')
doc = pq(htmlcode)
lx = etree.fromstring(htmlcode,etree.HTMLParser()) lx = etree.fromstring(htmlcode,etree.HTMLParser())
title = getTitle(lx) title = getTitle(lx)
dic = { dic = {
@@ -145,15 +142,15 @@ def main(number):
'outline': getOutline(number, title), 'outline': getOutline(number, title),
'runtime': getRuntime(lx), 'runtime': getRuntime(lx),
'director': getDirector(lx), 'director': getDirector(lx),
'actor': getActor(doc), 'actor': getActor(lx),
'release': getRelease(lx), 'release': getRelease(lx),
'number': getNum(lx), 'number': getNum(lx),
'cover': getCover(doc), 'cover': getCover(lx),
'imagecut': 1, 'imagecut': 1,
'tag': getTag(lx), 'tag': getTag(lx),
'extrafanart': getExtrafanart(htmlcode), 'extrafanart': getExtrafanart(htmlcode),
'label': getSerise(lx), 'label': getSerise(lx),
# 'actor_photo': getActorPhoto(doc), # 'actor_photo': getActorPhoto(lx),
'website': 'https://www.javbus.com/' + number, 'website': 'https://www.javbus.com/' + number,
'source': 'javbus.py', 'source': 'javbus.py',
'series': getSerise(lx), 'series': getSerise(lx),