历史价格

master
wkyuu 3 years ago
parent e1ba325f86
commit 67b0acb192

@ -38,12 +38,6 @@ def getsource(url):
return response return response
def useRequests(url): def useRequests(url):
def write2html(res):
filename = 'historyPrice.html'
with open(filename, mode = 'w+', encoding='utf-8') as fd:
fd.write(res)
try: try:
session = requests.Session() session = requests.Session()
res = session.get(url, headers = headers) res = session.get(url, headers = headers)
@ -52,7 +46,6 @@ def useRequests(url):
res.encoding = res.apparent_encoding res.encoding = res.apparent_encoding
res = etree.HTML(res.text) res = etree.HTML(res.text)
source = etree.tostring(res, encoding = 'utf-8', pretty_print = True, method = 'html').decode('utf-8') source = etree.tostring(res, encoding = 'utf-8', pretty_print = True, method = 'html').decode('utf-8')
# write2html(res)
return source return source
except BaseException as e: except BaseException as e:
print(e) print(e)
@ -61,7 +54,7 @@ def useRequests(url):
if __name__ == "__main__": if __name__ == "__main__":
jdurl = r"https://item.jd.com/10036840192083.html" jdurl = r"https://item.jd.com/10023043997421.html"
url = r"https://www.vveby.com/search?keyword=" + jdurl url = r"https://www.vveby.com/search?keyword=" + jdurl
print(url) print(url)
useRequests(url) useRequests(url)

@ -4,13 +4,36 @@ from lxml import etree
import settings import settings
import downloader import downloader
def myreplace(text):
return text.strip().replace(' ', '').replace("\r\n", '')
class historyPriceItem: class historyPriceItem:
def __init__(self, id): def __init__(self, id):
self.url = self.url = settings.HISTORY_PRICE_URL + str(id)
# self.response = downloader.useRequests(self.url)
self.response = etree.parse('historyPrice.html', etree.HTMLParser(encoding = 'utf-8'))
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 getTag(self) -> str:
reg = r"//div[@data-content='商品类别:']/text()"
tag = self.response.xpath(reg)[0]
tag = etree.HTML(tag)
tag = myreplace(tag)
return tag[5:]
def get
# tree = etree.tostring(response.xpath(reg)[0], encoding = 'utf-8', method = 'html').decode('utf-8')
if __name__ == '__main__': if __name__ == '__main__':
pass id = "10036840192083"
aitem = historyPriceItem(id)
aitem.gethistoryPrice()

@ -2,6 +2,8 @@
import os import os
from hyperlink import URL
# 修改要生成的文件名,下面的是默认,注意要用.csv结尾 # 修改要生成的文件名,下面的是默认,注意要用.csv结尾
FILENAME_CSV = { FILENAME_CSV = {
"牛奶": "milk.csv", "牛奶": "milk.csv",
@ -40,4 +42,5 @@ USER_AGENT = [
COOKIES_FILENAME = "cookies.json" COOKIES_FILENAME = "cookies.json"
# # 历史价格查询网站 vveby.com
HISTORY_PRICE_URL = r"https://www.vveby.com/search?keyword="
Loading…
Cancel
Save