做预测时,收集原始数据多,可能会提高数据预测的准确性。下面是收集了数量和注数,尾预测提供更多的可考虑的因素。
一、装载模块
import requests #爬虫库
import xlwt #写excel表库
import time #时间获取转换
from bs4 import BeautifulSoup #爬虫库
二、基本信息
url = 'http://datachart.500.com/pls/history/inc/history.php?limit=20000&start=2005001&end=2024360'
三、网页信息采集
def get_html(url):
#这是一个UA伪装,告诉网站你浏览器和操作系统系统
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
}
response = requests.get(url, headers = headers)#用爬虫对象获取网页内容
if response.status_code == 200:#对象状态码等于200说明获取网页内容成功
print('读取网页成功!')
return response.text#返回获取的网页内容