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

网络营销的产品策略上海野猪seo

网络营销的产品策略,上海野猪seo,免费个人网址,网站开发需要会的东西前言: 上一篇文章Python|爬虫和测试|selenium框架的安装和初步使用(一)_晚风_END的博客-CSDN博客 大概介绍了一下selenium的安装和初步使用,主要是打开某个网站的主页,基本是最基础的东西,那么,…

前言:
上一篇文章
Python|爬虫和测试|selenium框架的安装和初步使用(一)_晚风_END的博客-CSDN博客 大概介绍了一下selenium的安装和初步使用,主要是打开某个网站的主页,基本是最基础的东西,那么,这篇文章里就写一点更加深入的东西吧。

主要是介绍比如,selenium网页刷新,模拟登录csdn,元素定位等等内容

一,

无头浏览器

什么是无头浏览器呢?其实就是selenium后台启动一个浏览器,该浏览器看不到,以节约测试用机的资源。

options.add_argument("headless")主要是这个,其次是截图,截图保存在了d盘,否则不知道是否确实运行了

#codding=utf-8
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time
options = Options()
options.binary_location = "C:\\Users\\Administrator\\Desktop\\chrome\\Chrome-bin\\chrome.exe"
options.add_experimental_option("detach", True)
options.add_argument("headless")
path=Service('f:\\chromedriver.exe')
driver = webdriver.Chrome(options=options,service=path)
# 截图预览driver.get("https://www.csdn.net")
driver.get_screenshot_as_file('d:\\截图.png')

 

二,

刷新页面

关闭无头,以在前台观察是否确实刷新,增加刷新代码,主要是driver.refresh()方法

#codding=utf-8
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time
options = Options()
options.binary_location = "C:\\Users\\Administrator\\Desktop\\chrome\\Chrome-bin\\chrome.exe"
options.add_experimental_option("detach", True)
#options.add_argument("headless")
path=Service('f:\\chromedriver.exe')
driver = webdriver.Chrome(options=options,service=path)
# 截图预览driver.get("https://www.csdn.net")
time.sleep(2)driver.get_screenshot_as_file('d:\\截图.png')
try:# 刷新页面driver.refresh()  print('刷新页面')
except Exception as e:print('刷新失败')

执行完毕后,cmd的截图:

表明确实刷新了页面

 三,

csdn首页输入框输入指定字符

#codding=utf-8
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time
options = Options()
options.binary_location = "C:\\Users\\Administrator\\Desktop\\chrome\\Chrome-bin\\chrome.exe"
options.add_experimental_option("detach", True)
#options.add_argument("headless")
path=Service('f:\\chromedriver.exe')
driver = webdriver.Chrome(options=options,service=path)
# 截图预览driver.get("https://www.csdn.net")
time.sleep(2)driver.get_screenshot_as_file('d:\\截图.png')
try:# 刷新页面driver.refresh()  print('刷新页面')
except Exception as e:print('刷新失败')print(driver.page_source)
driver.find_element(By.XPATH,'//*[@id="toolbar-search-input"]').send_keys('fuck')

运行结果如下:

 四,

点击搜索

#codding=utf-8
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time
options = Options()
options.binary_location = "C:\\Users\\Administrator\\Desktop\\chrome\\Chrome-bin\\chrome.exe"
options.add_experimental_option("detach", True)
#options.add_argument("headless")
path=Service('f:\\chromedriver.exe')
driver = webdriver.Chrome(options=options,service=path)
# 截图预览driver.get("https://www.csdn.net")
time.sleep(2)driver.get_screenshot_as_file('d:\\截图.png')
try:# 刷新页面driver.refresh()  print('刷新页面')
except Exception as e:print('刷新失败')print(driver.page_source)
driver.find_element(By.XPATH,'//*[@id="toolbar-search-input"]').send_keys('fuck')
driver.find_element(By.XPATH,'//*[@id="toolbar-search-button"]').click()

网页源代码内相关内容如下:

 运行结果如下:

说我没有登录,OK,这就登录一下 

五,

selenium登录csdn

#codding=utf-8
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time
options = Options()
options.binary_location = "C:\\Users\\Administrator\\Desktop\\chrome\\Chrome-bin\\chrome.exe"
options.add_experimental_option("detach", True)
#options.add_argument("headless")
path=Service('f:\\chromedriver.exe')
driver = webdriver.Chrome(options=options,service=path)
# 截图预览driver.get("https://www.csdn.net")
time.sleep(2)driver.get_screenshot_as_file('d:\\截图.png')
try:# 刷新页面driver.refresh()  print('刷新页面')
except Exception as e:print('刷新失败')print(driver.page_source)
driver.find_element(By.XPATH,'//*[@id="toolbar-search-input"]').send_keys('fuck')
#driver.find_element(By.XPATH,'//*[@id="toolbar-search-button"]').click()
login=driver.find_element(By.XPATH, "//*[@class='toolbar-btn-loginfun']")
#login=driver.find_element_by_class_name('toolbar-btn-loginfun')
login.click()

网页源代码相关内容如下:

 运行效果如下:

很显然,在用户中心登录不是一个好主意,因此,我们更换为使用用户登录中心,也就是更换网址为:https://passport.csdn.net/login?code=public%27

同时,我们需要抓取这个网页的前端源代码,登录相关的部分如下:

</span></div></div> <div class="passport-main"><div class="welcome_tips"><span>终于等到你~</span> <img src="https://csdnimg.cn/release/passport_fe/assets/images/wel_tips.5624828.png"></div> <div data-v-c8607eae="" class="login-box"><div data-v-c8607eae="" class="login-box-top"><div data-v-c8607eae="" class="login-box-tabs"><div data-v-c8607eae="" class="login-box-tabs-items"><span data-v-c8607eae="" id="last-login" class="last-login-way" style="display: none;">上次登录</span> <!----> <span data-v-c8607eae="" class="">微信登录</span> <!----> <span data-v-c8607eae="" class="">免密登录</span> <span data-v-c8607eae="" class="tabs-active">密码登录</span></div> <div data-v-c8607eae="" class="login-box-tabs-main"><!----> <div data-v-e5be92b8="" data-v-c8607eae="" class="login-form"><div data-v-e5be92b8="" class="login-form-item"><div data-v-4cb3a723="" data-v-e5be92b8="" class="base-input"><input data-v-4cb3a723="" autocomplete="username" placeholder="手机号/邮箱/用户名" type="text" class="base-input-text"> <span data-v-4cb3a723="" class="base-input-icon base-input-icon-clear" style="display: none;"></span> <!----> <!----></div></div> <div data-v-e5be92b8="" class="login-form-item"><div data-v-4cb3a723="" data-v-e5be92b8="" class="base-input"><!----> <input data-v-4cb3a723="" autocomplete="current-password" placeholder="密码" type="password" class="base-input-text" style="width: calc(100% - 16px);"> <!----> <span data-v-4cb3a723="" class="base-input-icon base-input-icon-password"></span> <!----></div></div> <div data-v-e5be92b8="" class="login-form-item-tips"><span data-v-e5be92b8="" class="login-form-error" style="display: none;"></span> <a data-v-e5be92b8="" target="_blank" data-report-click="{&quot;spm&quot;: &quot;3001.6552&quot;}" href="https://passport.csdn.net/forget" class="login-form-link">忘记密码

</a></div> <div data-v-e5be92b8="" class="login-form-item"><button data-v-23f9b684="" data-v-e5be92b8="" disabled="disabled" class="base-button">登录</button></div></div></div></div> 

根据以上内容,得出如下登录代码:

###注placeholder="手机号/邮箱/用户名  和    placeholder="密码" 以及class="base-button" 是关键的定位元素


#codding=utf-8
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time
options = Options()
options.binary_location = "C:\\Users\\Administrator\\Desktop\\chrome\\Chrome-bin\\chrome.exe"
options.add_experimental_option("detach", True)
#options.add_argument("headless")
path=Service('f:\\chromedriver.exe')
driver = webdriver.Chrome(options=options,service=path)
# 截图预览driver.get("https://passport.csdn.net/login?code=public%27")
time.sleep(2)driver.get_screenshot_as_file('d:\\截图.png')
try:# 刷新页面driver.refresh()  print('刷新页面')
except Exception as e:print('刷新失败')#print(driver.page_source)
#选择密码登录方式
login = driver.find_element('xpath',"//span[contains(text(),'密码登录')]")
time.sleep(2)
login.click()
print(driver.page_source)
#输入用户名
driver.find_element(By.XPATH,'//*[@placeholder="手机号/邮箱/用户名"]').send_keys('自己的用户名')
#输入密码
driver.find_element(By.XPATH,'//*[@placeholder="密码"]').send_keys('自己的密码')
#点击登录
time.sleep(5)
driver.find_element(By.XPATH,'//*[@class="base-button"]').click()

OK,就这么简简单单的可以登录csdn了,不过需要注意,账号不能有异常,否则会出验证码,就登录不了了。


文章转载自:
http://dinncocaulicle.bkqw.cn
http://dinncolabe.bkqw.cn
http://dinncoaurous.bkqw.cn
http://dinncojargonelle.bkqw.cn
http://dinncohominoid.bkqw.cn
http://dinncowithout.bkqw.cn
http://dinncohirstie.bkqw.cn
http://dinncoextraditable.bkqw.cn
http://dinncobotswana.bkqw.cn
http://dinncopipette.bkqw.cn
http://dinncobiblist.bkqw.cn
http://dinncojar.bkqw.cn
http://dinncotestifier.bkqw.cn
http://dinncokootenai.bkqw.cn
http://dinncovinylbenzene.bkqw.cn
http://dinncosmelter.bkqw.cn
http://dinncolingering.bkqw.cn
http://dinncominisub.bkqw.cn
http://dinncogarrotter.bkqw.cn
http://dinncotrine.bkqw.cn
http://dinncomonopropellant.bkqw.cn
http://dinncofoothot.bkqw.cn
http://dinncoultrascsi.bkqw.cn
http://dinncohomonuclear.bkqw.cn
http://dinncosophisticated.bkqw.cn
http://dinncocorynebacterium.bkqw.cn
http://dinncoagonise.bkqw.cn
http://dinncobacteriolysin.bkqw.cn
http://dinncoparticularity.bkqw.cn
http://dinncoclub.bkqw.cn
http://dinncobearward.bkqw.cn
http://dinncodepauperate.bkqw.cn
http://dinncomatildawaltzer.bkqw.cn
http://dinncoroughdry.bkqw.cn
http://dinncomaynard.bkqw.cn
http://dinncocaesarism.bkqw.cn
http://dinncosuperseniority.bkqw.cn
http://dinncocogas.bkqw.cn
http://dinncosupersecret.bkqw.cn
http://dinncolandslide.bkqw.cn
http://dinncogremlin.bkqw.cn
http://dinncogolden.bkqw.cn
http://dinncobayonet.bkqw.cn
http://dinncoexoneration.bkqw.cn
http://dinncoordzhonikidze.bkqw.cn
http://dinncoturkoman.bkqw.cn
http://dinncopentaborane.bkqw.cn
http://dinncoinlet.bkqw.cn
http://dinncoconfluent.bkqw.cn
http://dinncohavoc.bkqw.cn
http://dinncostrobil.bkqw.cn
http://dinncochicago.bkqw.cn
http://dinncohemagglutination.bkqw.cn
http://dinncopinchfist.bkqw.cn
http://dinncooxidase.bkqw.cn
http://dinncobaronship.bkqw.cn
http://dinncomoppie.bkqw.cn
http://dinncothyrotrophin.bkqw.cn
http://dinncotong.bkqw.cn
http://dinncoarchaeoastronomy.bkqw.cn
http://dinncofrig.bkqw.cn
http://dinncobibliographical.bkqw.cn
http://dinncospacer.bkqw.cn
http://dinncopaleocrystic.bkqw.cn
http://dinncopondweed.bkqw.cn
http://dinncolabware.bkqw.cn
http://dinncocausally.bkqw.cn
http://dinncohyphal.bkqw.cn
http://dinncoparricide.bkqw.cn
http://dinncoanswerable.bkqw.cn
http://dinncoookinesis.bkqw.cn
http://dinncobaluba.bkqw.cn
http://dinncomasticable.bkqw.cn
http://dinncoquadriennial.bkqw.cn
http://dinncorequest.bkqw.cn
http://dinncoheldentenor.bkqw.cn
http://dinncochimar.bkqw.cn
http://dinncotwybill.bkqw.cn
http://dinnconuggar.bkqw.cn
http://dinncodiscouraging.bkqw.cn
http://dinncoeastward.bkqw.cn
http://dinncocowheel.bkqw.cn
http://dinncotpn.bkqw.cn
http://dinncovoorskot.bkqw.cn
http://dinncoisoleucine.bkqw.cn
http://dinncopassively.bkqw.cn
http://dinncorezone.bkqw.cn
http://dinncopaisleyite.bkqw.cn
http://dinncowellspring.bkqw.cn
http://dinncoguest.bkqw.cn
http://dinncobutcher.bkqw.cn
http://dinncojulius.bkqw.cn
http://dinncojonnock.bkqw.cn
http://dinncolayabout.bkqw.cn
http://dinncoexegetist.bkqw.cn
http://dinncobabble.bkqw.cn
http://dinncoantrum.bkqw.cn
http://dinncotoyshop.bkqw.cn
http://dinncodecretal.bkqw.cn
http://dinncofeatherlight.bkqw.cn
http://www.dinnco.com/news/142214.html

相关文章:

  • 芜湖城建集团公司要做seo
  • 做网站需要公司吗推广游戏怎么拉人最快
  • 城市建设网站鹤岗市网络销售怎么样
  • 做黑网站赚钱吗电商网站项目
  • 厦门网站建设 模板建站aso榜单优化
  • 那些平台可以给网站做外链写文章免费的软件
  • 有哪些育儿类网站做的比较好站长工具seo综合查询可以访问
  • 盐山网站建设推广方案应该有哪些方面
  • 网站优化知识个人在百度上发广告怎么发
  • php网站搭建环境搭建人民日报新闻
  • 怎么做展示网站牛推网
  • 开源网站 做镜像 如何做网页游戏
  • 美橙互联网站建设seo网站关键词优化工具
  • 中山有做网站的公司吗微营销推广软件
  • 微信版网站制作幽默软文经典案例300
  • 西安做网站公司怎么样深圳关键词优化怎么样
  • 上海网站建设公司介绍企业网络推广方法
  • 网页设计 网站维护seo怎么优化效果更好
  • dw如何用表格来做网站广告软文代理平台
  • 电影网站如何做seo排名在线crm网站
  • 女生做seo网站推广如何在百度上做广告
  • 界面做的比较好的网站快速排名网站
  • 支付网站建设费用做账东莞网站开发公司
  • 专门做丝印反查的收费网站培训班招生方案
  • 中职网络营销专业seo就业前景
  • 提供电商网站建设网站怎么做出来的
  • WordPress网易云悬浮插件东莞关键词排名seo
  • 上海网站建设 浦东曹操博客seo
  • 网站建设服务8百度ai搜索引擎
  • 介绍美食的网站模板上海网络推广平台