Python Demo 01

来源:互联网 发布:中科院 网络空间安全 编辑:程序博客网 时间:2024/05/21 17:22

Python Demo

import numpy as npimport pandas as pdfrom pandas_datareader import data, wbimport requestsfrom bs4 import BeautifulSoup# http://quote.eastmoney.com/sz002026.htmlheader = {    'Connection': 'Keep-Alive',    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',    'Accept-Language': 'zh-CN,zh;q=0.8,en;q=0.6',    'User-Agent': 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0)'}# fund_url = 'http://fund.eastmoney.com/f10/000001.html'share_url = 'http://quote.eastmoney.com/sz002026.html'res = requests.get(share_url, headers=header, timeout=10)# ISO-8859-1# var = res.encoding# print(var)# re = res.text.encode("gbk")# print(res.text)res.encoding = 'gbk'f = open(r'C:\Users\want\Desktop\sz002026.html', 'w', encoding='gbk')f.write(res.text)f.close()soup = BeautifulSoup(res.text, 'html.parser')# print(soup)# fund_name = soup.html.head.title.string## print(fund_name)share_name = soup.find('h2', id="name").stringshare_code = soup.find('b', id="code").stringprint(share_name)print(share_code)jk = soup.find('td', id="gt5").stringprint(jk)
原创粉丝点击