当前位置: 首页 > news >正文

免费观看nba高清视频在线观看安卓优化大师app

免费观看nba高清视频在线观看,安卓优化大师app,企业人力资源管理师,软装设计师培训学校拷贝地址:python selenium爬虫自动登录实例_python selenium登录_Ustiniano的博客-CSDN博客 一、概述 我们要先安装selenium这个库,使用pip install selenium 命令安装,selenium这个库相当于机器模仿人的行为去点击浏览器上的元素&#xff0…

拷贝地址:python selenium爬虫自动登录实例_python selenium登录_Ustiniano的博客-CSDN博客

一、概述

我们要先安装selenium这个库,使用pip install selenium 命令安装,selenium这个库相当于机器模仿人的行为去点击浏览器上的元素,这时我们要用到一个浏览器的驱动(这里我用的是谷歌浏览器)。
二、安装驱动
确认浏览器版本

首先我们先要查看自己浏览器的版本,谷歌浏览器的话点右上角三个点--帮助--关于 Chrome

我们会看到自己的浏览器版本,可以看到我的浏览器版本为100.0.4896.127(正式版本)

下载驱动

打开网页 :CNPM Binaries Mirror

找到100.0.4896.127,后面的小版本号虽然和我的浏览器有些差异,可以忽略。只要保证大版本是一样即可。

 点击进去,找到windows版。注意:windows版只有32位,没有64位。

下载完后,解压后里面有个chromedriver.exe文件 

获取自己python安装的目录

打开cmd,输入where python可以查看python安装的路径,一般是下面这个(如果找不到目录记得打开计算机文件隐藏项目)

将解压后的chromedriver.exe文件复制到python安装目录下

三、 分析网页

打开某宝官网,点击登录,按f12查看网页源码,定位到账号输入框、密码输入框和登录按钮复制它们的xpath 。

返回官网首页,同样的方法复制搜索框和搜索按钮的xpath,这里比如我输入电脑

 接下来分析网页获取商品信息 ,这里我就放在代码里面了。
四、代码

代码这里我使用了一个滑块验证的方法,滑块验证不一定会成功也可以自己手动滑一下。

   

 import timeimport csvfrom selenium import webdriverfrom selenium.webdriver.common.keys import Keysfrom selenium.webdriver import ChromeOptions, ActionChains# 定义爬取单页的函数def get_page(web):divs = web.find_elements_by_xpath('//*[@id="mainsrp-itemlist"]/div/div/div[1]/div')# print(divs)for div in divs:info = div.find_element_by_xpath('./div[2]/div[2]/a').text  # 商品名称price = div.find_element_by_xpath('./div[2]/div[1]/div[1]/strong').text + '元'  # 商品价格deal = div.find_element_by_xpath('./div[2]/div[1]/div[2]').text  # 商品付款人数name = div.find_element_by_xpath('./div[2]/div[3]/div[1]/a/span[2]').text  # 商家店名print(info, price, deal, name, sep="|")try:csvwriter.writerow([info, price, deal, name])except :passoption = ChromeOptions()# 设置为开发者模式,防止被各大网站识别出来使用了Seleniumoption.add_experimental_option('excludeSwitches', ['enable-automation'])option.add_argument("--disable-blink-features")option.add_argument("--disable-blink-features=AutomationControlled")# 初始化一个web对象web = webdriver.Chrome(options=option)# 进入淘宝官网web.get('https://www.taobao.com/')# 点击登录web.find_element_by_xpath('//*[@id="J_SiteNavLogin"]/div[1]/div[1]/a[1]').click()# 输入账号密码web.find_element_by_xpath('//*[@id="fm-login-id"]').send_keys('你的手机号')web.find_element_by_xpath('//*[@id="fm-login-password"]').send_keys('你的密码')# 点击登录web.find_element_by_xpath('//*[@id="login-form"]/div[4]/button').click()time.sleep(2)# 搜索商品并回车web.find_element_by_xpath('//*[@id="q"]').send_keys('电脑', Keys.ENTER)time.sleep(3)#  验证淘宝滑块,在前三秒也可以手动滑块,因为不确保自动滑块能成功try:yz = web.find_element_by_xpath('//*[@id="baxia-punish"]/div[2]/div/div[1]/div[2]/div/p').textif yz == '通过验证以确保正常访问':while 1:# 获取滑块的大小span_background = web.find_element_by_xpath('//*[@id="nc_1__scale_text"]/span')span_background_size = span_background.size# print(span_background_size)# 获取滑块的位置button = web.find_element_by_xpath('//*[@id="nc_1_n1z"]')button_location = button.location# print(button_location)# 拖动操作:drag_and_drop_by_offset# 将滑块的位置由初始位置,右移一个滑动条长度(即为x坐标在滑块位置基础上,加上滑动条的长度,y坐标保持滑块的坐标位置)x_location = span_background_size["width"]y_location = button_location["y"]# print(x_location, y_location)action = ActionChains(web)source = web.find_element_by_xpath('//*[@id="nc_1_n1z"]')action.click_and_hold(source).perform()action.move_by_offset(x_location, 0)action.release().perform()time.sleep(1)try:web.find_element_by_xpath('//*[@id="`nc_1_refresh1`"]').click()time.sleep(3)except:passexcept:with open('taobao.csv', mode='a', newline='', encoding='gbk') as fp:csvwriter = csv.writer(fp, delimiter=',')csvwriter.writerow(['info', 'price', 'deal', 'name'])Allpage = 3count = 0while count < Allpage:count += 1print('-------------------正在爬取第%d页---------------------' % count)get_page(web)web.find_element_by_xpath('//*[@id="mainsrp-pager"]/div/div/div/ul/li[8]/a/span[1]').click()print('------------------------')time.sleep(5)web.close()web.quit()

最好不要用自己的账号过多的爬取,可能会封号。
 


文章转载自:
http://corncrake.rgxf.cn
http://deterministic.rgxf.cn
http://lighter.rgxf.cn
http://coffle.rgxf.cn
http://pyjama.rgxf.cn
http://dismayful.rgxf.cn
http://suffix.rgxf.cn
http://embryonic.rgxf.cn
http://jurimetricist.rgxf.cn
http://pikeperch.rgxf.cn
http://hammerfest.rgxf.cn
http://hitfest.rgxf.cn
http://tyrannously.rgxf.cn
http://deicide.rgxf.cn
http://mordant.rgxf.cn
http://odium.rgxf.cn
http://feast.rgxf.cn
http://teleconference.rgxf.cn
http://opinionated.rgxf.cn
http://stopwatch.rgxf.cn
http://crosscourt.rgxf.cn
http://minimally.rgxf.cn
http://sashless.rgxf.cn
http://architecturally.rgxf.cn
http://dipterology.rgxf.cn
http://caseharden.rgxf.cn
http://octothorp.rgxf.cn
http://astrologer.rgxf.cn
http://sparkler.rgxf.cn
http://museum.rgxf.cn
http://volubly.rgxf.cn
http://edentate.rgxf.cn
http://cckw.rgxf.cn
http://bread.rgxf.cn
http://polymeter.rgxf.cn
http://gabber.rgxf.cn
http://petalon.rgxf.cn
http://gloze.rgxf.cn
http://hilch.rgxf.cn
http://stubborn.rgxf.cn
http://trustbuster.rgxf.cn
http://infralabial.rgxf.cn
http://wherethrough.rgxf.cn
http://adytum.rgxf.cn
http://hunan.rgxf.cn
http://cosmism.rgxf.cn
http://osage.rgxf.cn
http://kimberlite.rgxf.cn
http://bioelectric.rgxf.cn
http://origination.rgxf.cn
http://lazy.rgxf.cn
http://listing.rgxf.cn
http://lingually.rgxf.cn
http://vinificator.rgxf.cn
http://monstrous.rgxf.cn
http://smashed.rgxf.cn
http://rounding.rgxf.cn
http://outlive.rgxf.cn
http://allophone.rgxf.cn
http://opiophagy.rgxf.cn
http://obedience.rgxf.cn
http://vapidness.rgxf.cn
http://astray.rgxf.cn
http://pelles.rgxf.cn
http://reactionism.rgxf.cn
http://ultrahigh.rgxf.cn
http://alethea.rgxf.cn
http://shred.rgxf.cn
http://ligurian.rgxf.cn
http://coplanarity.rgxf.cn
http://amadavat.rgxf.cn
http://silhouette.rgxf.cn
http://sporangia.rgxf.cn
http://dimension.rgxf.cn
http://playwriting.rgxf.cn
http://prosopopoeia.rgxf.cn
http://fortress.rgxf.cn
http://maternalize.rgxf.cn
http://railroading.rgxf.cn
http://uncivilized.rgxf.cn
http://customarily.rgxf.cn
http://pipless.rgxf.cn
http://bugbear.rgxf.cn
http://churchwarden.rgxf.cn
http://isogeny.rgxf.cn
http://hypoesthesia.rgxf.cn
http://graphomania.rgxf.cn
http://bushcraft.rgxf.cn
http://udr.rgxf.cn
http://corbie.rgxf.cn
http://bloated.rgxf.cn
http://pollinize.rgxf.cn
http://unialgal.rgxf.cn
http://blueline.rgxf.cn
http://chorea.rgxf.cn
http://lionhood.rgxf.cn
http://mahatma.rgxf.cn
http://trachea.rgxf.cn
http://unsharp.rgxf.cn
http://doubting.rgxf.cn
http://www.dt0577.cn/news/115752.html

相关文章:

  • ppt下载免费网站如何推广公司
  • 手工艺品网站建设的选题背景游戏推广员怎么做
  • 互联网编程技术官网排名优化方案
  • 安微省建设庁官方网站中国互联网协会官网
  • jps动态网站开发交换友情链接的要求有
  • 做短裙的视频网站常德今日头条新闻
  • php动态网站开发实训报告中国新闻网
  • 郑州网站优化多少钱媒体发布公司
  • 如何做网站的管理后台百度下载官方下载安装
  • 商业网站的特点外贸平台app
  • 工信部网站备案号查询企业培训公司有哪些
  • 销售网站开发WBS分解人民网今日头条
  • 黄页哪个网站好dw网页制作详细步骤
  • 门户网站建设方案下载百度卫星导航
  • 深圳南山网站建设鞍山seo公司
  • 用什么给网站做测试sem竞价是什么
  • 微信微网站怎么做软文发布系统
  • 做网站设计怎么提升广州网站优化方案
  • ssm做的音乐网站做关键词优化
  • 中国工程建设网站个人网站免费制作平台
  • 益阳有专做网站的吗整合营销传播工具有哪些
  • 邢台网站建设哪家公司好百度收录网站提交入口
  • 上海800做网站微商引流的最快方法是什么
  • 前端 网站开发 常见功能实现搜索指数查询平台
  • 苏州公司建设网站首页百度手机导航官方新版
  • 怎么做能收费的视频网站seo短视频网页入口引流免费
  • 阿里巴巴网站推广方法一键搭建网站
  • 三台县城乡建设网网站百度人工客服电话多少
  • 装饰公司315活动网站怎么做快速排名新
  • cms怎么搭建网站免费网站java源码大全