利用requests-BeautifulSoup&Json 爬取股票代码、名称、当日开收盘价格

一、实现目标

本文利用股城网(https://hq.gucheng.com/gpdmylb.html)提供的股票代码数据,经由同花顺网(http://stockpage.10jqka.com.cn/000001/ )检索交易结束后的当日开盘价格、收盘价格。
其中,股城网的网页数据(目标:股票代码、股票名称)通过BeautifulSoup抓取,同花顺网的目标数据(交易结束后的当日开盘价格、收盘价格)转化成json字典后提取,最后录入EXCEL文件。

二、使用步骤

1.引入库

import requests
import json
import bs4
from bs4 import BeautifulSoup
import traceback
import re
import openpyxl
from datetime import datetime

2.读入数据

def getHTMLText(url):
try:
    headers={'user-agent':'Mozilla/5.0'}
    r = requests.get(url, headers=headers,timeout = 30)
    r.raise_for_status()
    r.encoding = r.apparent_encoding
    print(r.status_code)
    return r.text
except:
    return ""



def getStockList(infoDict,stock_code_url):
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值