You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.6 KiB

# -*- coding: utf-8 -*-
from lxml import etree
import downloader
import pipelines
import settings
3 years ago
class historyPriceItem:
def __init__(self, id):
3 years ago
self.url = settings.HISTORY_PRICE_URL + str(id)
self.response = pipelines.gethtml(downloader.useRequests(self.url))
# self.response = etree.parse('historyPriceMore.html', etree.HTMLParser(encoding = 'utf-8'))
# self.response = etree.parse('historyPrice.html', etree.HTMLParser(encoding = 'utf-8'))
3 years ago
def gethistoryPrice(self) -> list:
reg = r"//div[@class='container']"
item = self.response.xpath(reg)[0]
item = etree.tostring(item, encoding = 'utf-8', method = 'html').decode('utf-8')
def updateTime() -> str:
reg = r"//div[@class='p3']/p[@class='tips']/text()"
time = self.response.xpath(reg)[0]
time = pipelines.myreplace(time, mode = 'strip')
return str(time[5:])
def priceTrend() -> str:
check = 'timeline-text'
if not check in item: # 用于判断有无历史价格记录
return ''
reg = r"//div[@class='timeline-text']/p/text()"
regList = self.response.xpath(reg)
price = ''
for i in range(0, len(regList), 2):
price += pipelines.myreplace(regList[i]) + pipelines.myreplace(regList[i + 1]) + ';'
return price
priceHistoryList = [updateTime(), priceTrend()]
return priceHistoryList
if __name__ == '__main__':
# id = "10036840192083"
id = "11564571796" # More
3 years ago
aitem = historyPriceItem(id)
print(aitem.gethistoryPrice())