python爬虫项目-爬取雪球网金融数据(关注、持续更新)
(一)python金融数据爬虫项目
爬取目标:雪球网(起始url:https://xueqiu.com/hq#exchange=CN&firstName=1&secondName=1_0&page=1)
爬取内容:雪球网深沪股市情况
使用工具:requests库实现发送请求、获取响应。
json格式的动态加载数据实现数据解析、提取。
pymysql进行数据存储
思路:对该网站的动态加载数据的请求方式进行控制变量的发送请求,最终得到实际有效的参数。
项目重点:使用抓包工具分析发送数据请求到json格式的cookie数据,这是此次动态抓取的重点
直接放代码(详细说明在注释里,欢迎同行相互交流、学习~):
import requests
import json
import pymysql class mysql_conn(object):
# 魔术方法, 初始化, 构造函数
def __init__(self):
self.db = pymysql.connect(host='127.0.0.1', user='root', password='abc123', port=3306, database='py1011')
self.cursor = self.db.cursor()
# 执行modify(修改)相关的操作
def execute_modify_mysql(self, sql):
self.cursor.execute(sql)
self.db.commit()
# 魔术方法, 析构化 ,析构函数
def __del__(self):
self.cursor.close()
self.db.close() headers = {
# 使用抓包工具分析发送数据请求到json格式的cookie数据,这是此次动态抓取的重点
'Cookie': xq_a_token=584d0cf8d5a5a9809761f2244d8d272bac729ed4; xq_r_token=98f278457fc4e1e5eb0846e36a7296e642b8138a;
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36',
}
url = 'https://xueqiu.com/v4/statuses/public_timeline_by_category.json?since_id=-1&max_id=-1&count=10&category=111' response = requests.get(url,headers=headers) res_dict = json.loads(response.text) list_lsit = res_dict['list'] db ={}
for list_item_dict in list_lsit:
data_dict = json.loads(list_item_dict['data']) db['id'] = data_dict['id']
db['title'] = data_dict['title']
db['description'] = data_dict['description']
db['target'] = data_dict['target']
try:
sql = 'insert into xueqiu (uid,title,description,target) values ("{id}","{title}","{description}","{traget}")'.fromart(**db)
mc = mysql_conn()
mc.execute_modify_mysql(sql)
except:
pass
python爬虫项目-爬取雪球网金融数据(关注、持续更新)的更多相关文章
- Python爬虫项目--爬取链家热门城市新房
本次实战是利用爬虫爬取链家的新房(声明: 内容仅用于学习交流, 请勿用作商业用途) 环境 win8, python 3.7, pycharm 正文 1. 目标网站分析 通过分析, 找出相关url, 确 ...
- Python爬虫项目--爬取自如网房源信息
本次爬取自如网房源信息所用到的知识点: 1. requests get请求 2. lxml解析html 3. Xpath 4. MongoDB存储 正文 1.分析目标站点 1. url: http:/ ...
- Python爬虫项目--爬取猫眼电影Top100榜
本次抓取猫眼电影Top100榜所用到的知识点: 1. python requests库 2. 正则表达式 3. csv模块 4. 多进程 正文 目标站点分析 通过对目标站点的分析, 来确定网页结构, ...
- Python爬虫项目--爬取某宝男装信息
本次爬取用到的知识点有: 1. selenium 2. pymysql 3 pyquery 正文 1. 分析目标网站 1. 打开某宝首页, 输入"男装"后点击"搜索&q ...
- selenium爬取qq空间,requests爬取雪球网数据
一.爬取qq空间好友动态数据 # 爬取qq空间好友状态信息(说说,好友名称),并屏蔽广告 from selenium import webdriver from time import sleep f ...
- Python爬虫之爬取慕课网课程评分
BS是什么? BeautifulSoup是一个基于标签的文本解析工具.可以根据标签提取想要的内容,很适合处理html和xml这类语言文本.如果你希望了解更多关于BS的介绍和用法,请看Beautiful ...
- [Python爬虫] Selenium爬取新浪微博客户端用户信息、热点话题及评论 (上)
转载自:http://blog.csdn.net/eastmount/article/details/51231852 一. 文章介绍 源码下载地址:http://download.csdn.net/ ...
- from appium import webdriver 使用python爬虫,批量爬取抖音app视频(requests+Fiddler+appium)
使用python爬虫,批量爬取抖音app视频(requests+Fiddler+appium) - 北平吴彦祖 - 博客园 https://www.cnblogs.com/stevenshushu/p ...
- Python爬虫之爬取站内所有图片
title date tags layut Python爬虫之爬取站内所有图片 2018-10-07 Python post 目标是 http://www.5442.com/meinv/ 如需在非li ...
随机推荐
- 【计算机篇】Office 2016 for Mac 安装和破解教程
免责声明 请亲们支持正版.这教程旨在分享,供参考. 为啥写这篇文章 对于大多数使用 Mac 的用户而言,虽然有苹果自家的办公软件,但功能少,用起来不舒服.而 Offer 2016 版的需要登录激活购买 ...
- [Swift]LeetCode443. 压缩字符串 | String Compression
Given an array of characters, compress it in-place. The length after compression must always be smal ...
- [Swift]LeetCode808. 分汤 | Soup Servings
There are two types of soup: type A and type B. Initially we have N ml of each type of soup. There a ...
- [Swift]LeetCode830. 较大分组的位置 | Positions of Large Groups
In a string S of lowercase letters, these letters form consecutive groups of the same character. For ...
- [Swift]LeetCode833. 字符串中的查找与替换 | Find And Replace in String
To some string S, we will perform some replacement operations that replace groups of letters with ne ...
- [Swift]LeetCode905. 按奇偶排序数组 | Sort Array By Parity
Given an array A of non-negative integers, return an array consisting of all the even elements of A, ...
- [Swift]LeetCode1025. 除数博弈 | Divisor Game
Alice and Bob take turns playing a game, with Alice starting first. Initially, there is a number N o ...
- vue总结
1.库和框架的区别 库:jquery 本质上就是一些列函数的集合,将一些函数封装到一个独立的就是文件中 在使用的jquery的时候,是由开发人员说了算的,也就是说开发人员起到了主导作用,而jquery ...
- Android studio的错误:radle sync failed: Cause: failed to find target android-21 :
这个错误在Android studio中经常出现,特别是你在编译不同的app的时候,到底是什么原因会导致该错误产生呢? 首先看错误信息,是找不到目标android版本-21导致的,这就很明显了,你的目 ...
- spring boot -spring data-redis
//添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...