问财网 股票信息爬虫案例
股票爬虫案例
from selenium import webdriver
from my_fake_useragent import UserAgent
from lxml import etree
import json"""
序号,股票代码,股票简称,现价(元),涨跌幅(%)
"""def selenium_test():# 配置Chrome浏览器chrome_options = webdriver.ChromeOptions() # 创建一个配置ua = UserAgent().random # 随机抽取一个uaprint('user-agent: ', ua)chrome_options.add_argument('user-agent=' + str(ua))chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])chrome_options.add_argument('blink-settings=imagesEnabled=false')chrome_options.add_argument('--headless') # 无头模式chrome_options.add_argument('--disable-gpu') # 禁用gpu加速# 发送请求url = 'http://www.iwencai.com/stockpick/search?typed=1&preParams=&ts=1&f=1&qs=result_rewrite&selfsectsn=&querytype=stock&searchfilter=&tid=stockpick&w=%E6%8D%A2%E6%89%8B%E7%8E%87%3E5%25&queryarea='driver = webdriver.Chrome(options=chrome_options)driver.get(url)# 获取源码html = driver.page_source# 保存网页源码到demo.html文件# with open('demo.html', 'w', encoding='utf8') as fp:# fp.write(html)# 解析数据html = etree.HTML(html)tr_list_1 = html.xpath("//div[@class='static_con']//table//tbody/tr")tr_list_2 = html.xpath("//div[@class='scroll_tbody_con']//tbody/tr")info_all_1 = list()info_all_2 = list()#for tr in tr_list_1:info_line = list()xuhao = tr.xpath("./td[1]/div/text()")[0]bianhao = tr.xpath("./td[3]/div/text()")[0]name = tr.xpath("./td[4]/div/a/text()")[0]info_line.append(xuhao)info_line.append(bianhao)info_line.append(name)info_all_1.append(info_line)# print(info_all_1)for tr in tr_list_2:info_line = list()xianjia = tr.xpath("./td[1]/div/text()")[0]zhangdiefu = tr.xpath("./td[2]/div/text()")[0]info_line.append(xianjia)info_line.append(zhangdiefu)info_all_2.append(info_line)# print(info_all_2)info_all = list()for sub_list_1, sub_list_2 in zip(info_all_1, info_all_2): # 同时遍历两个列表, 合并他们的每一个元素为一个列表list_temp = sub_list_1 + sub_list_2info_all.append(list_temp)print(info_all) # 最终结果# 保存结果# with open('data.txt', 'w', encoding='utf-8') as fp:# json.dump(info_all, fp)# time.sleep(3) # 等待driver.quit() # 关闭if __name__ == '__main__':selenium_test()
问财网 股票信息爬虫案例相关推荐
- 有缘网分布式爬虫案例2
有缘网分布式爬虫案例: 修改 spiders/youyuan.py 在spiders目录下增加youyuan.py文件编写我们的爬虫,使其具有分布式: # -*- coding:utf-8 -*-fr ...
- 有缘网分布式爬虫案例
有缘网分布式爬虫案例 # clone github scrapy-redis源码文件 git clone https://github.com/rolando/scrapy-redis.git# 直接 ...
- 【Python爬虫学习】八、股票数据定向爬虫(2020年1月31日成功爬取中财网,百度股市通web版404了)
功能描述: 目标:获取股票的名称和交易信息 输出:保存到文件中 程序结构设计: 步骤1:从中财网http://quote.cfi.cn/stockList.aspx获取股票列表 步骤2:根据股票列表获 ...
- 问财同花顺spider(爬虫)2接上篇没有实现的页面滚动问题
问财同花顺spider(爬虫)2接上篇没有实现的页面滚动问题 上一篇的文章 看过我之前文章的可以知道无法实现鼠标滚动问题 这里滚动页面运用到查找元素拖动到元素位置,由于更新数据按照30个更新,使用设置 ...
- 利用pyhton爬虫(案例3)--X房网的小房子们
写了个小案例,顺便复习一下以前学的知识点. PS:复试之前绝不写爬虫案例了(对于现在的我来说,费脑又花时间),再写我吃XX. 文章目录 爬取X房网二手房信息 爬取步骤 URL特征 查看HTML页面源代 ...
- [Python爬虫案例]-中国古诗网
[Python爬虫案例]-中国古诗网 看懂代码,你需要相关知识 爬虫必备知识 只是想得到目标的话,直接运行就好了 import requests import re import jsondef pa ...
- 问财同花顺spider(爬虫)
这个问财–爬虫必须可用的 话不多说开始 如今用的是js绕行反爬机制,打开页面是这样的 真实页面: 缺点 页面滚动一直没有实现,然后就是需要手动滚动到页面底部 唉 有大佬看到后希望你和我交流一下哟 联系 ...
- Day26.爬虫案例一:拍拍网
爬虫案例一:拍拍网 文章目录 爬虫案例一:拍拍网 前言 一. 拍拍网案例 1.1 首先将需要的包导入 1.2 创建一个爬取拍拍网的类 1.3 实现爬虫类并做测试. 总结 前言 本文主要是通过学习的知识 ...
- 1688官网以图搜图爬虫案例
阿里1688图片搜索爬虫案例 图片上传接口 sign生成接口 数据详情接口 代码部分 网址 :https://www.1688.com/ 在1688.com 使用程序完成图片上传功能. 注意:2021 ...
最新文章
- 网络安全性——IPSEC(续思科设备实现)
- 5G会用什么样的语音通信方案?
- 操作系统思考 第二章 进程
- 数据库高可用架构 转载
- kido机器人用流量吗_拉在手心的爱-----乐视 KIDO有问必答的4G智能儿童手表评测...
- 在udp聊天器里如何给飞秋发消息
- app源码+php+l,android商城APP全套源码(服务端+客户端)
- iostream类 - C++输入输出(一)
- 我的Android进阶之旅------Android中编解码学习笔记
- 七代处理器装win7_七代cpu为什么不支持win7?
- 支持mrp软件的手机(MTK手机)检测
- 普通二重积分计算的难点、易错点
- opencv-python图形图像处理入门基础知识
- 微信网页授权页面获取不到code
- Python3,多线程爬取某瓣小电影~ ~
- 关于网站项目计划书的写法
- Mysql 基础练习大全(建表到基本查询)
- Linux下Docker安装微信文件传输问题
- 为ThinkCentre M910t-NO76重装Windows7(64位)系统
- 资产管理之输油管线RFID资产管理解决方案,避免人为破坏资产-新导智能