selenium——爬取qq空间说说
采用可见即可爬的方法
- 模拟登录
- 抓取说说内容
自己的个人说说网址:
https://user.qzone.qq.com/你的qq号/311
一、打开登录界面
切换iframe
1.由于登录按钮是在iframe上,所以第一步需要把定位器切换到iframe上2.用switch_to_frame方法切换,此处有id属性,可以直接用id定位切换
<iframe id="login_frame" name="login_frame" height="100%" scrolling="no" width="100%"
iframe是HTML标签,iframe 元素会创建包含另外一个文档的内联框架(即行内框架)。
定位输入框
分别为账户,密码,登录按钮:
<div class="login_form"><form id="loginform" autocomplete="off" name="loginform" action="" method="post" target="0" style="margin:0px;"><div class="uinArea" id="uinArea"><label class="input_tips_focus" id="uin_tips" for="u" data-onlyqq="QQ号码" style="display: none;">支持QQ号/邮箱/手机号登录</label><div class="inputOuter"><input type="text" class="inputstyle" id="u" name="u" value="" tabindex="1"> <a class="uin_del" id="uin_del" href="javascript:void(0);" style="display: block;"></a></div><ul class="email_list" id="email_list" style="display: none;"></ul></div><div class="pwdArea" id="pwdArea"><label class="input_tips_focus" id="pwd_tips" for="p" style="display: none;">密码</label><div class="inputOuter"><input type="password" class="inputstyle password" id="p" name="p" value="" maxlength="16" tabindex="2"></div><div class="lock_tips" id="caps_lock_tips" style="display: none;"><span class="lock_tips_row"></span> <span>大写锁定已打开</span></div></div><div class="verifyArea" id="verifyArea"><div class="verifyinputArea" id="verifyinputArea"><label class="input_tips" id="vc_tips" for="verifycode">验证码</label><div class="inputOuter"><input name="verifycode" type="text" class="inputstyle verifycode" id="verifycode" value="" tabindex="3"></div></div><div class="verifyimgArea" id="verifyimgArea"><img class="verifyimg" id="verifyimg" title="看不清,换一张"> <a tabindex="4" href="javascript:void(0);" class="verifyimg_tips">看不清,换一张</a></div></div><div class="submit"><a class="login_button" href="javascript:void(0);" hidefocus="true"><input type="submit" tabindex="6" value="登 录" class="btn" id="login_button"></a></div></form></div>
抓取说说
登录成功后:
正文、时间:
正文
<pre style="display:inline;" class="content">难顶</pre>
时间
<a class="c_tx c_tx3 goDetail" title="2020年8月14日 4:05" href="http://user.qzone.qq.com/......00.1">2020年8月14日</a>
图片:
<img oncontextmenu="this.src=this.src.replace('&t=5','');this.οncοntextmenu=null" src="http://photogz.photo.store.qq.com/psc?/V11Ep9yN4ddHYK/ruAMsa53pVQWN7FLK88i5oRsaiK.zcPKT7JgEb4ZUf2fSUsSHu0ThjC17PNy8oTedGmxeele9Dm8THSfXqHl*3WTZ*sFTUtGuIDEnKuntCw!/b&bo=sgK0BrICtAYRECc!&rf=mood_app&t=5" pic-index="0" data-src="http://photogz.photo.store.qq.com/psc?/V11Ep9yN4ddHYK/ruAMsa53pVQWN7FLK88i5oRsaiK.zcPKT7JgEb4ZUf2fSUsSHu0ThjC17PNy8oTedGmxeele9Dm8THSfXqHl*3WTZ*sFTUtGuIDEnKuntCw!/b&bo=sgK0BrICtAYRECc!" data-isphoto="1" class="" data-limit="400,300" height="300">
css选择器用法
- 标签选择器:直接写标签名,比如title就表示选择 title 这个标签。
- 类选择器:以小数点开头,比如.nav就表示选择所有 class 属性为nav的 DOM 元素。
- ID 选择器:以 # 开头,比如#content就表示选择 id 属性为content的 DOM 元素。(根据css 规范,id 属性值应该是唯一的,不能存在其他具有相同 id 的元素)
- 属性选择器:写在[]括号内,如a[href=“https://example.org”]
- 伪元素选择器:伪元素选择器来自Css3规范,使用两个冒号引导。最常用的应该是title::text这个伪元素。(不过 css3 规范里好像没有 text 伪元素)
- 关系选择器:基于关系的选择器-MDN
完整代码
from selenium import webdriver
import time
import pandas as pd#options = webdriver.ChromeOptions()
#options.add_argument('headless')# 浏览器不提供可视化页面
browser = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe")
browser.maximize_window()#获取说说正文和时间
def get_info(qq):browser.get('https://user.qzone.qq.com/你的qq账号/311')'''1.由于登录按钮是在iframe上,所以第一步需要把定位器切换到iframe2.用switch_to_frame方法切换,此处有id属性,可以直接用id定位切换另外:切到frame中之后,我们便不能继续操作主文档的元素'''browser.switch_to.frame('login_frame') #iframe的切换默认支持id和namebrowser.find_element_by_id('switcher_plogin').click()#切换账号密码登录browser.find_element_by_id('u').clear() #先清空输入框browser.find_element_by_id('u').send_keys(qq)browser.find_element_by_id('p').clear()browser.find_element_by_id('p').send_keys('upassword')browser.find_element_by_id('login_button').click()time.sleep(3) #稍等一下等登录browser.switch_to.frame('app_canvas_frame')contents = browser.find_elements_by_class_name('content')times = browser.find_elements_by_css_selector('.c_tx.c_tx3.goDetail')print(contents[0].text) #打印第一条看看print(times[0].text)data = {}content_info = []time_info = []for i in range(len(list(contents))):content_info.append(contents[i].text)time_info.append(times[i].text)data['content'] = content_infodata['time'] = time_infodf = pd.DataFrame(data)df.to_csv('./qq.csv',index = False,encoding='utf_8_sig')browser.close()get_info('你的qq号')
结果:
selenium——爬取qq空间说说相关推荐
- python爬取加密qq空间_使用python+selenium爬取qq空间好友动态
使用python+selenium爬取qq空间好友动态 分析过程如下: 要想用selenium登陆qq空间,必须点击账号密码登陆按钮然后再填写账号密码登陆. 1.PNG 点击账号密码按钮后跳转到如下页 ...
- python整合selenium爬取QQ空间访客记录
利用周末放假两天时间写了个QQ空间访客记录的爬虫,在这里分享出来:本文将会把要做的步骤都列出来,一步一步的实现这个爬虫程序. 特别注明: 本程序仅供学习交流目的 请勿用于不可描述的事情 爬取过程中需要 ...
- python selenium爬取QQ空间说说
准备工作 安装selenium, pyquery, json模块. 使用的是火狐浏览器,所以还要安装geckodriver, 下载好后,把geckodirver.exe文件放在python.exe同一 ...
- python3 使用selenium爬取QQ空间说说信息
使用PhantomJS,事先需要下载PhantomJS from selenium import webdriver import time#使用selenium driver = webdriver ...
- selenium爬取QQ空间
这几天在看<从零开始学python网络爬虫>中的模拟浏览器篇,对其中的爬取好友说说比较感兴趣,不过书中只是爬取每个好友第一页说说,因此我稍微改进了下(发书名是尊重作者,不过个人认为这本书讲 ...
- python + selenium +chrome爬取qq空间好友说说并存入mongodb数据库
python + selenium +chrome爬取qq空间好友说说并存入mongodb数据库 准备阶段 在正式开始在前需要先准备好做爬虫的工具,本例使用chrome无头浏览器进行爬取工作,也可使用 ...
- python爬取好友qq空间_python + selenium +chrome爬取qq空间好友说说并存入mongodb数据库...
title: python + selenium +chrome爬取qq空间好友说说并存入mongodb数据库 准备阶段 在正式开始在前需要先准备好做爬虫的工具,本例使用chrome无头浏览器进行爬取 ...
- php取qq空间说说id,Python爬取qq空间说说的实例代码
具体代码如下所示: #coding:utf-8 #!/usr/bin/python3 from selenium import webdriver import time import re impo ...
- selenium爬取qq音乐
今日学习(解析selenium爬取qq音乐,附带解析数据) 点此查看原博客 爬取QQ音乐官网指定歌手的前5首歌曲的基本信息和前五百条热门评论: selenium中文网点此学习selenium 简而言之 ...
最新文章
- anaconda常用指令,更新查看添加下载源等
- (zhuan) Recurrent Neural Network
- ncnn windows
- linux中here文档,Linux下Bash Heredoc(Here document)的用法及基本示例
- 苹果WWDC前瞻之iOS 13更新最受关注;微软发布基于区块链的去中心化身份识别系统;小米成立了新集团质量办公室……...
- 如何用控制台启动一个wcf服务
- SharePoint Manager 2007 国外高人写的管理工具,有特色,对学习moss有帮助
- 2021年中国窗口句柄市场趋势报告、技术动态创新及2027年市场预测
- mysql期中考试题及答案_mysql 查询 练习题及答案
- JavaScript控制文字方向
- CNC:CNC计算机数控系统技术之斯沃数控仿真软件简介、软件界面(顶部栏、中间工具栏、左边栏、CNC工作区、液晶屏工作区、系统控制面板)之详细攻略
- 论保留地址与私有地址
- AutoCad 批量打印
- Dtcms修改PC站分享到手机端后访问打开手机版的当前页面
- 描述数据库表关系之间的ER图(1对1,1对多,多对1,多对多等关系)
- VMWARE虚拟机启动失败,模块“Disk”启动失败
- 评卷系统-答题卡制作参考网站
- 中文文本分类——商品评论情感判别
- vue页面报错: Uncaught ReferenceError: Login is not defined at HTMLButtonElement.onclick
- layui复选框默认选中
热门文章
- FastCGI原理与应用[转]
- android sdk引入 微信分享_Android分享 ShareSDK微信分享详解
- jsapi 支付缺少appid ¬ify_url
- 计算机通识之TCP/IP协议簇(二)
- 多元线性回归算法预测房价【人工智能】
- 我这些年我用过的12 个企业级开源系统,亲测非常好用,非常适合公司开发
- cad怎么将图层后置_Auto CAD2014图层后置快捷键是什么啊?
- html文字抖动效果,CSS实现TikTok文字抖动效果示例
- 利用gpu加速神经网络算法,为什么用gpu 模型训练
- java基础周报_java第四周周报