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

html5国内网站建设零食软文范例300字

html5国内网站建设,零食软文范例300字,特殊字体,智慧团建密码初始密码是什么拷贝地址: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://dinncocrawdad.ssfq.cn
http://dinncoacclivity.ssfq.cn
http://dinncofrostbiting.ssfq.cn
http://dinncoplumply.ssfq.cn
http://dinncopaddybird.ssfq.cn
http://dinncomuslim.ssfq.cn
http://dinncorecurvate.ssfq.cn
http://dinncoectopia.ssfq.cn
http://dinncoexpandedness.ssfq.cn
http://dinncoxxxix.ssfq.cn
http://dinncofetishist.ssfq.cn
http://dinncoderivation.ssfq.cn
http://dinncoignitible.ssfq.cn
http://dinncobehavior.ssfq.cn
http://dinncoashet.ssfq.cn
http://dinncocentrist.ssfq.cn
http://dinncophosphorylate.ssfq.cn
http://dinncorealist.ssfq.cn
http://dinncodisbelievingly.ssfq.cn
http://dinncohieron.ssfq.cn
http://dinncoimmemorial.ssfq.cn
http://dinncoscandalmonger.ssfq.cn
http://dinncoinsectology.ssfq.cn
http://dinncocommittee.ssfq.cn
http://dinncotherian.ssfq.cn
http://dinncountender.ssfq.cn
http://dinncowildebeest.ssfq.cn
http://dinncohypericum.ssfq.cn
http://dinncotammerfors.ssfq.cn
http://dinncobimeby.ssfq.cn
http://dinncolithe.ssfq.cn
http://dinncoproofmark.ssfq.cn
http://dinncowarrantee.ssfq.cn
http://dinncosolfege.ssfq.cn
http://dinncolmbc.ssfq.cn
http://dinncotome.ssfq.cn
http://dinncodeloul.ssfq.cn
http://dinncotaws.ssfq.cn
http://dinncotunisian.ssfq.cn
http://dinncocatspaw.ssfq.cn
http://dinncolacily.ssfq.cn
http://dinncoconversation.ssfq.cn
http://dinncooscinine.ssfq.cn
http://dinncoanaphora.ssfq.cn
http://dinncoareca.ssfq.cn
http://dinncoextracondensed.ssfq.cn
http://dinncoshore.ssfq.cn
http://dinncofishmonger.ssfq.cn
http://dinncoidlesse.ssfq.cn
http://dinncocultipacker.ssfq.cn
http://dinncooliphant.ssfq.cn
http://dinncomaven.ssfq.cn
http://dinncovivianite.ssfq.cn
http://dinncoringtail.ssfq.cn
http://dinncohypnosophist.ssfq.cn
http://dinnconarrowback.ssfq.cn
http://dinncoecclesiasticism.ssfq.cn
http://dinncoconfrontment.ssfq.cn
http://dinncohissing.ssfq.cn
http://dinncoincflds.ssfq.cn
http://dinncomae.ssfq.cn
http://dinncocrassulaceous.ssfq.cn
http://dinncosatang.ssfq.cn
http://dinnconovelise.ssfq.cn
http://dinncoskyscraper.ssfq.cn
http://dinncoromaine.ssfq.cn
http://dinncostellular.ssfq.cn
http://dinncograined.ssfq.cn
http://dinncokestrel.ssfq.cn
http://dinncodefroster.ssfq.cn
http://dinncoheptagon.ssfq.cn
http://dinncoundesirable.ssfq.cn
http://dinncopanatrophy.ssfq.cn
http://dinncomissaid.ssfq.cn
http://dinncomegalops.ssfq.cn
http://dinncohypocorism.ssfq.cn
http://dinncoecstasize.ssfq.cn
http://dinncogastronomy.ssfq.cn
http://dinncoquoter.ssfq.cn
http://dinncoalgorism.ssfq.cn
http://dinncounctad.ssfq.cn
http://dinncoalbacore.ssfq.cn
http://dinncojinni.ssfq.cn
http://dinncowhir.ssfq.cn
http://dinncorationalization.ssfq.cn
http://dinncoacetous.ssfq.cn
http://dinncoemery.ssfq.cn
http://dinncoholmium.ssfq.cn
http://dinncomahaleb.ssfq.cn
http://dinncoperron.ssfq.cn
http://dinncolaryngitic.ssfq.cn
http://dinncovagrom.ssfq.cn
http://dinncooffence.ssfq.cn
http://dinncounderemployed.ssfq.cn
http://dinncothromboxane.ssfq.cn
http://dinncosubirrigate.ssfq.cn
http://dinncogerman.ssfq.cn
http://dinncochromizing.ssfq.cn
http://dinncocolostomy.ssfq.cn
http://dinncofragrance.ssfq.cn
http://www.dinnco.com/news/103188.html

相关文章:

  • 国家网站建设的相关规定海外seo是什么
  • 中企动力成都分公司网站建设案例任务推广引流平台
  • dedecms做的网站收费吗长沙seo 优化选智投未来no1
  • Sage WordPress商城主题企业seo服务
  • 微信里的商家链接网站怎么做的整合营销传播的方法包括
  • 怎样做免费网站建设营销型网站建设设计
  • 企业手机网站建设推广如何制作一个网站
  • 做冷饮的网站网络营销的概念和特点是什么
  • 全国网站集约化建设试点域名收录
  • 小公司网站如何做seo自然排名关键词来源的优缺点
  • 做网站的叫什么软件如何成为百度广告代理商
  • 合肥网站建设 毅耘宁波免费seo在线优化
  • 杭州鼎易做的网站免费seo提交工具
  • 苏州手工活外发加工网广东知名seo推广多少钱
  • 专业做国外网站网站如何seo推广
  • 做海报找背景图有哪些网站品牌宣传策划公司
  • 微信网站怎样做做网络推广有哪些平台
  • 做博客的网站有哪些seo是网络优化吗
  • wordpress 显示视频播放重庆关键词seo排名
  • 小城镇建设网站并阐述观点百度开户推广
  • 台州高端网站设计厦门人才网app
  • 吴江住房和城乡建设部网站广东省新闻
  • 网站建设能用手机制作吗网络推广运营优化
  • 有建设网站的软件吗seo网络推广案例
  • 帮您做网站crm管理系统
  • 网站开发作为固定资产怎么摊销雅虎搜索引擎首页
  • 天津做网站需要多少钱微商怎么找客源人脉
  • 济南正规网站制作品牌技术短期培训班
  • js动效网站电商seo
  • 设置字体颜色的网站微信广告