抓取可盈可乐跟非小号网站的数据

__author__ = 'WYL'
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


import urllib
import urllib.request
import re
import os
import time
import threading
import sys


orig_url = 'https://www.coincola.com/buy/ETH'
feixiaohao_url = 'https://www.feixiaohao.com/currencies/ethereum/'

def getcoincola_data(__url):
#print(__url)
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
req = urllib.request.Request(url=__url, headers=headers)
response = urllib.request.urlopen(req)

"""
res_text = urllib.request.urlopen(req)
f = open('response.txt','wb')
f.write(res_text.read())
f.close()
"""

#print(response.read().decode('UTF-8'))
#<a class="td-username " href="/user/1000081673">limei0215<br><span class="is-realname">Verified</span></a>
data = response.read().decode('UTF-8')
pattern = re.compile(r'<td class="td-price">\d\d\d\d CNY</td>',re.S)
items = re.findall(pattern,data)
contents = []
for item in items:
#print(item)
item_price = re.findall(r'\d\d\d\d',item)
#print(item_price[0])
contents.append(item_price[0])

#print(len(contents))
#for i in contents:
# print(i)

#old=sys.stdout
log_txt = open('20180319.txt','a')
sys.stdout = log_txt

print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))
print('coincola buy:',float(contents[0]),' ',float(contents[1]),' ',float(contents[2]),' ', \
'percent %.3f %%' % (float(abs(float(contents[1]) - float(contents[0])))/float(contents[0])) \
)



#============================================================================================================
fxh_req = urllib.request.Request(url=feixiaohao_url, headers=headers)
fxh_response = urllib.request.urlopen(fxh_req)
fxh_data = fxh_response.read().decode('UTF-8')
#print(fxh_data)
fxh_pattern = re.compile(r'<div class="coinprice">¥\d,\d\d\d<span class="',re.S)
fxh_items = re.findall(fxh_pattern,fxh_data)
#print(fxh_items)
for fxh_item in fxh_items:
#print(fxh_item)
fxh_item_price = re.findall(r'\d,\d\d\d',fxh_item)
#print(fxh_item_price)
fxh_price = float(fxh_item_price[0].replace(',',''))
print('feixiaohao eth: ',fxh_price,' 溢价:','percent %.3f %%'%(float(contents[1])/fxh_price))
#============================================================================================================

global timer
timer = threading.Timer(120, getcoincola_data, [orig_url])
timer.start()


if __name__ == '__main__':
#geturllist(orig_url)
timer = threading.Timer(1, getcoincola_data, [orig_url])
timer.start()

 

转载于:https://www.cnblogs.com/lan1145557260/p/8598670.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值