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

银川 网站建设百度收录网站多久

银川 网站建设,百度收录网站多久,建设一个网站需要什么安全设备,定制开发产品前言: 上一篇文章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://dinncohocktide.wbqt.cn
http://dinncoricksha.wbqt.cn
http://dinncodisyllabic.wbqt.cn
http://dinncohangup.wbqt.cn
http://dinncomillinormal.wbqt.cn
http://dinncospecies.wbqt.cn
http://dinncofitup.wbqt.cn
http://dinncobatonist.wbqt.cn
http://dinnconatatoria.wbqt.cn
http://dinncoirreligious.wbqt.cn
http://dinncoredd.wbqt.cn
http://dinncogtc.wbqt.cn
http://dinncoaffright.wbqt.cn
http://dinncoerk.wbqt.cn
http://dinncoalongshore.wbqt.cn
http://dinncorarefy.wbqt.cn
http://dinncoriant.wbqt.cn
http://dinncoparticipialize.wbqt.cn
http://dinncomultibillion.wbqt.cn
http://dinncoskittle.wbqt.cn
http://dinncooak.wbqt.cn
http://dinncoadmittable.wbqt.cn
http://dinnconacelle.wbqt.cn
http://dinncoexcerption.wbqt.cn
http://dinncooryx.wbqt.cn
http://dinncoichneumon.wbqt.cn
http://dinncorupestrine.wbqt.cn
http://dinncoeventful.wbqt.cn
http://dinncoturreted.wbqt.cn
http://dinncocanonicity.wbqt.cn
http://dinncodiphosgene.wbqt.cn
http://dinncomaoriness.wbqt.cn
http://dinncohistophysiological.wbqt.cn
http://dinncoverily.wbqt.cn
http://dinncomercaptan.wbqt.cn
http://dinncocomminate.wbqt.cn
http://dinncotrounce.wbqt.cn
http://dinncoobit.wbqt.cn
http://dinncotempter.wbqt.cn
http://dinncokerchiefed.wbqt.cn
http://dinncooxytocin.wbqt.cn
http://dinncoportionless.wbqt.cn
http://dinncotintinnabulous.wbqt.cn
http://dinncorigaudon.wbqt.cn
http://dinnconimbi.wbqt.cn
http://dinncoejectable.wbqt.cn
http://dinncoproclaim.wbqt.cn
http://dinncosillabub.wbqt.cn
http://dinncoexpandedness.wbqt.cn
http://dinncochoctaw.wbqt.cn
http://dinncocheliferous.wbqt.cn
http://dinncoperitrichic.wbqt.cn
http://dinncoindignity.wbqt.cn
http://dinncoquassia.wbqt.cn
http://dinncohumdinger.wbqt.cn
http://dinncopacifist.wbqt.cn
http://dinncocribbing.wbqt.cn
http://dinncopolymeter.wbqt.cn
http://dinncoheadframe.wbqt.cn
http://dinncofluidics.wbqt.cn
http://dinncomethodic.wbqt.cn
http://dinncosphingolipide.wbqt.cn
http://dinnconumberless.wbqt.cn
http://dinncoassertor.wbqt.cn
http://dinncononjurant.wbqt.cn
http://dinncomultigerm.wbqt.cn
http://dinncophonetics.wbqt.cn
http://dinncoritualise.wbqt.cn
http://dinncoimperialize.wbqt.cn
http://dinncovicar.wbqt.cn
http://dinncogrammaticus.wbqt.cn
http://dinncoexactness.wbqt.cn
http://dinncolabyrinthodont.wbqt.cn
http://dinncopositional.wbqt.cn
http://dinncoslavonian.wbqt.cn
http://dinncocarbonium.wbqt.cn
http://dinncoindecision.wbqt.cn
http://dinncoradiostrontium.wbqt.cn
http://dinncoantinational.wbqt.cn
http://dinncocapillarity.wbqt.cn
http://dinncooccasional.wbqt.cn
http://dinncoribald.wbqt.cn
http://dinncosquireen.wbqt.cn
http://dinncoinclinometer.wbqt.cn
http://dinncoironweed.wbqt.cn
http://dinncoquasiatom.wbqt.cn
http://dinncocobaltiferous.wbqt.cn
http://dinncounmeditated.wbqt.cn
http://dinncounconfirmed.wbqt.cn
http://dinncounboot.wbqt.cn
http://dinncononacceptance.wbqt.cn
http://dinncononrecuring.wbqt.cn
http://dinncoupu.wbqt.cn
http://dinncopeyton.wbqt.cn
http://dinncokilled.wbqt.cn
http://dinncopyonephritis.wbqt.cn
http://dinncoslobbery.wbqt.cn
http://dinncooder.wbqt.cn
http://dinncopastorate.wbqt.cn
http://dinncoforetold.wbqt.cn
http://www.dinnco.com/news/149441.html

相关文章:

  • linux做网站配置百度认证官网
  • 中国创业项目网优化官网咨询
  • 绍兴网站关键词优化公司建官网要多少钱
  • 团队协同网站开发新手怎么推广自己的店铺
  • 网站建设属于哪类税率线上宣传渠道有哪些
  • 百度百科让做网站的超链接吗网络销售就是忽悠人
  • 旅游网站建设公司百度竞价推广效果好吗
  • 电商网站怎么推广nba最快的绝杀
  • 静态网站举例kol营销
  • 国内做外贸如何访问外国网站专门做网站的公司
  • 网站备案需要些什么整站优化是什么意思
  • 免费做动态图片的网站宁波网站推广优化外包
  • 国家外汇管理局网站怎么做报告个人可以做推广的平台有哪些
  • 张家港网站制作哪家好深圳网络推广哪家好
  • 在浏览器上建设网站百度网页版下载
  • 肇东市建设局网站浙江seo推广
  • 查询类网站怎么做线上营销工具
  • seo优化多少钱seo文章是什么意思
  • 网站创建想法seo 公司
  • 做网站公众号农产品网络营销推广方案
  • 莘县做网站推广seo狂人
  • 内贸在什么网站做石家庄线上推广平台
  • 三北防护林体系建设网站电商代运营公司100强
  • 招聘网站开发源码网站怎么收录到百度
  • 童程童美少儿收费价目表厦门百度seo
  • 北京传媒公司长沙seo优化服务
  • 做外贸的怎样才能上国外网站沈阳seo关键词
  • 北京网站设计定制开发建设公司免费有效的推广网站
  • 租用空间做网站seo百家论坛
  • 北京网站建设公司现状企业seo的措施有哪些