python3 [爬虫实战] 微博爬虫京东客服之Selenium + Chrom浏览器的使用(上)
2017-08-22 00:37
876 查看
先暂时记录一下
首先 Chrom浏览器一定要匹配好, 不能在百度搜索中下载最新的谷歌浏览器,我现在下的是版本50的浏览器。匹配的chromedriver.exe 是2.9的。32位的同样也使用64位的。需要把chromedriver.exe 安装在谷歌浏览器的安装目录下,路径是:C:\Program Files (x86)\Google\Chrome\Application
与chrome.exe是同一个目录级别, 最后再把该路径设置在环境变量中C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe
上面的是一个大坑,因为之前用的一直是PhantomJS 没有界面的浏览器
其二:简单的爬取微博内容,很坑比的微博,登陆验证还需要图片。
到这里就懵逼了。
一开始简单的使用搜索功能,单个元素的使用直接用chrome下的xpath直接用就行
后面加了些自动登录的代码,到登录那里还需要验证输入图片上的玩意
直接GG
现在给出代码片吧,里面分两块内容,有兴趣的可以稍微研究研究
# -*- coding: utf-8 -*- # @Time : 2017/8/21 21:52 # @Author : 蛇崽 # @Email : 17193337679@163.com # @File : SeleniumTestVedio.py 根据视频进行练习 from selenium import webdriver from selenium import webdriver import os import time chromedriver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe" os.environ["webriver.chrome.driver"] = chromedriver browser = webdriver.Chrome(chromedriver) webdriver.PhantomJS url = "https://www.weibo.com/" browser.get(url) time.sleep(5) # inputId = browser.find_element_by_class_name('W_input') # inputId.send_keys('@京东客服') # time.sleep(1) # button = browser.find_element_by_xpath('//*[@id="weibo_top_public"]/div/div/div[2]/a') # button.click() # time.sleep(3) # browser.execute_script('window.scrollTo(0,document.body.scrollHeight)') # # 立即登录按钮 # btnLogin = browser.find_element_by_xpath('//*[@id="pl_weibo_direct"]/div/div[4]/div/p/span[2]/a[1]') # btnLogin.click() #手机号登录 phoneLogin = browser.find_element_by_xpath('//*[@id="loginname"]') phoneLogin.send_keys('微博账号') # 密码 phonePwd = browser.find_element_by_xpath('//*[@id="pl_login_form"]/div/div[3]/div[2]/div/input') phonePwd.send_keys('微博密码') time.sleep(3) # 登录按钮 btnNext = browser.find_element_by_xpath('//*[@id="pl_login_form"]/div/div[3]/div[6]/a') btnNext.click()
以上注释的一段是一个搜索功能,搜索京东客服这玩意,上好几个任务没有完成的内容, 下面一段没有注释的是微博登陆的代码, 在chrome 浏览器下面看,还是稍微有点成就感的, 因为这个selenium 之前没怎么很熟悉的用过
不过selenium 还是需要认真的看看文档的
再做一下总结:
针对微博爬虫,京东数据爬虫,使用ajax的加载,用selenium 或者 使用维持cookie池,ip代理池,就好。另外崔庆才大神的视频我也有部分,大家想要的可以问我百度云
好困, 先睡了。相关文章推荐
- python3[爬虫实战] 使用selenium,xpath爬取京东手机(下)
- python3[爬虫实战] 使用selenium,xpath爬取京东手机(上)
- python3[爬虫实战] 使用selenium,xpath爬取京东手机(下)
- python3[爬虫实战] 使用selenium,xpath爬取京东手机(上)
- Python爬虫实战03:用Selenium模拟浏览器爬取淘宝美食
- python爬虫:使用Selenium模拟浏览器行为
- python3 [爬虫入门实战]爬虫之selenium 安装设置与初步使用
- 浅谈python爬虫使用Selenium模拟浏览器行为
- 使用python+selenium制作浏览器爬虫,彻底解决ajax异步加载问题(待更新)
- python3[爬虫实战] 爬虫之requests爬取新浪微博京东客服
- Python爬虫入门实战七:使用Selenium--以抓取QQ空间好友说说为例
- [Python爬虫]使用Selenium操作浏览器订购火车票
- python3 [爬虫入门实战] 爬虫之使用selenium 爬取百度招聘内容并存mongodb
- Python爬虫实战之使用Scrapy爬起点网的完本小说
- Python爬虫使用Selenium+PhantomJS抓取Ajax和动态HTML内容
- Python+Selenium实现微博自动化爬虫
- Python+Selenium爬虫实战一《将QQ今日话题发布到个人博客》
- python+selenium调用浏览器(IE-Chrome-Firefox)实现爬虫功能
- Python爬虫学习(9):Selenium的使用
- Python爬虫实战(2):爬取京东商品列表