# -*- coding: utf-8 -*-
import requests
import sys
import re
import io
import xlwt
import xlrd
import time
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')
def getHtml(url): #用requests获得网页
# 构造头部
headers = {'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36'}
cook={'cookies':
"****************"}
time.sleep(0.2)
gethtml = requests.get(url, headers=headers,cookies=cook)
return gethtml.text
def biaoName():#表的列表标题
sheet.write(0, 0, "序号")
sheet.write(0, 1, "基金名称")
sheet.write(0, 2, "日期")
sheet.write(0, 3, "操作")
return biaoName
url="http://www.zhitouxing.com/my_strg"
resp = getHtml(url)
FoundNames = re.findall("<tr id='.*?' style='' ><td>(.*?)</td>", resp, re.S) # 正则表达式
FoundTimes = re.findall("</a></td><td>(.*?)<br/>", resp, re.S)
FoundMakes = re.findall("<span style='color:red;'>今天定投</span></td><td><span>(.*?)</span>", resp, re.S)
workbook = xlwt.Workbook( encoding="utf-8" )
sheet = workbook.add_sheet('智投星获取信息')
biaoName()
for i in range(0, len(FoundNames), 1):
sheet.write(i+1, 0, i+1)
sheet.write(i+1, 1, FoundNames[i])
sheet.write(i+1, 2, FoundTimes[i])
sheet.write(i+1, 3, FoundMakes[i])
i=i+ 1
workbook.save(r"C:\Users\fuxingyu\Desktop\智投星.xls")
代码打包成exepyinstaller -F ztx.py
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。