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

大型电子商务网站建设方案推广方案

大型电子商务网站建设方案,推广方案,网站你懂我意思正能量不用下载视频,网站建设服务费如何做会计分录Selenium本来是一个自动测试工具,用于模拟用户对网站进行操作。在爬虫领域也有其用处。 一、下载安装Selenium及附属插件 pip install Selenium 安装完成后还需要安装一个浏览器驱动,来让python能启动浏览器。 如果是Edge或者其他基于Chromium的浏览器…

       Selenium本来是一个自动测试工具,用于模拟用户对网站进行操作。在爬虫领域也有其用处。

一、下载安装Selenium及附属插件

pip install Selenium

        安装完成后还需要安装一个浏览器驱动,来让python能启动浏览器。

        如果是Edge或者其他基于Chromium的浏览器(如下面的百分浏览器),我们先查看Chromium版本号:

        

        这里以Edge为例,版本为126.0.2592.68,进入下面的网址,咱们就选最后一个,win版本,解压之后的exe文件就是我们需要的东西,你可以把它放在python解释器目录,项目目录或者其他你找得到的地方。

chromedriver.storage.googleapis.com/index.html

 

 

 二、selenium的使用

(一)、第一个程序

先来试试第一个程序,它会使用edge打开百度(第一打开时间可能有点长(10s?),并且打开后不久就会自动关闭)然后输出抬头的数据:

import timefrom selenium.webdriver import Edge   # Edge 可以换成 Chrome/Firefox(火狐)/Ie/BlackBerry······url = 'http://www.baidu.com'
web = Edge()
web.get(url)
print(web.title)
time.sleep(50)

 (二)、以站酷为例

        接下来,我们尝试模拟一下从站酷ZCOOL-设计师互动平台-打开站酷,发现更好的设计!中搜索"网站设计",并打开第一个和第二个文章的全过程

        在selenium中,我们所有操作,看到的都是已经经过js处理过的页面,也就是说,他是所见即所得。以站酷为例,站酷首页的文章都是二次请求得到的,源代码中没有,用以下代码就能清楚看到。会输出True False,如果不是的话,尝试更改文章名或者延长time.sleep时间,以保证网站完全加载。

import timeimport requests
from selenium.webdriver import Edge  # Edge 可以换成 Chrome/Firefox(火狐)/Ie/BlackBerry······headers = {# 用户代理,某些网站验证用户代理,微微改一下,如果提示要验证码之类的,使用它"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome""/118.0.0.0 Safari/537.36",
}url = 'https://www.zcool.com.cn/'
web = Edge()
web.get(url)
# print(web.page_source)
time.sleep(8)
print('字体合集' in web.page_source)    # 字体合集是一个文章名
with requests.get(url=url, headers=headers) as resp:resp.encoding = "utf-8"  # 当页面乱码改这里# print(resp.text)print('字体合集' in resp.text)# 字体合集是一个文章名

 需要模拟的行为流程

 模拟代码

 通过以下代码即可获取所需内容:通常来说,人怎么想,就怎么用selenium访问页面。

import timefrom selenium.webdriver import Edge  # Edge 可以换成 Chrome/Firefox(火狐)/Ie/BlackBerry······
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keysurl = 'https://www.zcool.com.cn/'
web = Edge()
web.get(url)
time.sleep(3)  # 等几秒使得网站完全加载
# 已经进入网站,找到搜索框,输入数据并回车搜索。
# By有By.ID、By.NAME、By.XPATH、By.CSS_SELECTOR等
search_box = web.find_element(By.XPATH, '//*[@id="headerSearchInput"]')  # 直接通过检查元素中的xpath获得位置
search_box.send_keys("网站设计")
# 方法一、点击搜索,
# search = web.find_element(By.CLASS_NAME, '_search-icon_1wwm7_457')
# search.click()
# 方法二,按下回车,也可以直接放一块:search_box.send_keys("网站设计",Keys.ENTER)
search_box.send_keys(Keys.ENTER)
time.sleep(3)
# 打开两个文章
img = web.find_element(By.XPATH, '//*[@id="__next"]/main/div/div/div[2]/section[2]/section/section/div[1]/div[1]')
img.click()
img = web.find_element(By.XPATH, '//*[@id="__next"]/main/div/div/div[2]/section[2]/section/section/div[2]/div[1]')
img.click()
time.sleep(2)
# 遇到不能按F12打开控制台和没有右键菜单的情况,应该是拦截了快捷键,点击地址栏然后按F12即可
# 切换窗口获得所需内容
web.switch_to.window(web.window_handles[1])
text = web.find_element(By.XPATH, '//*[@id="__next"]/main/div/section/div[1]')
print(text.text)
web.switch_to.window(web.window_handles[2])
text = web.find_element(By.XPATH, '//*[@id="__next"]/main/div/section/div[1]')
print(text.text)

(三)、其他代码

        selenium不太适合做能长久使用的脚本,但短时间内用一两次还是可以的,下面是一些以后可能用到的函数示例

from selenium.webdriver import Edge  # Edge 可以换成 Chrome/Firefox(火狐)/Ie/BlackBerry······
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.options import Options
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWaitopt = Options()
opt.add_argument("--disable-blink-features=AutomationControlled")  # 防止服务器知道是selenium打开的。url = 'https://www.zhihu.com/'
web = Edge(options=opt)
web.get(url)
web.implicitly_wait(10)  # 隐式等待,接下来所有的查找都至少等10s,如果10s内查到了就继续,否则报错
el = WebDriverWait(web, 10, 0.5).until(  # 显示等待,浏览器等待10s每0.5s轮询一次,搜索,如果检测到返回元素EC.presence_of_element_located((By.NAME, '所需的name'))
)ActionChains(web).move_to_element_with_offset(el, xoffset=255, yoffset=30)  # 模拟点击el元素向右255像素向下30像素的位置

总结:

        selenium优点自然是使用比较简单,怎么访问网站就怎么写代码即可,但是访问速度比较慢,需要等待页面JS加载。


文章转载自:
http://wanjiawhitish.bpcf.cn
http://wanjiaplacentiform.bpcf.cn
http://wanjiafiddling.bpcf.cn
http://wanjiadaryl.bpcf.cn
http://wanjiamanstopper.bpcf.cn
http://wanjiaairworthy.bpcf.cn
http://wanjiatoggle.bpcf.cn
http://wanjiameetinghouse.bpcf.cn
http://wanjiaburgonet.bpcf.cn
http://wanjiamagnetometive.bpcf.cn
http://wanjiadirectorate.bpcf.cn
http://wanjiacontignation.bpcf.cn
http://wanjiaanew.bpcf.cn
http://wanjiashavetail.bpcf.cn
http://wanjiaphenomenon.bpcf.cn
http://wanjiainductee.bpcf.cn
http://wanjianosogenetic.bpcf.cn
http://wanjiathrive.bpcf.cn
http://wanjiakakotopia.bpcf.cn
http://wanjiamanitou.bpcf.cn
http://wanjiaresurgam.bpcf.cn
http://wanjiapardi.bpcf.cn
http://wanjiaelectively.bpcf.cn
http://wanjiagermany.bpcf.cn
http://wanjiakcb.bpcf.cn
http://wanjiaslapdashery.bpcf.cn
http://wanjiahymnography.bpcf.cn
http://wanjiareplica.bpcf.cn
http://wanjiabioethics.bpcf.cn
http://wanjiaapposable.bpcf.cn
http://wanjiasemantic.bpcf.cn
http://wanjiaunborn.bpcf.cn
http://wanjiahaematogen.bpcf.cn
http://wanjiageomancer.bpcf.cn
http://wanjiaglasswork.bpcf.cn
http://wanjiascribe.bpcf.cn
http://wanjiakdc.bpcf.cn
http://wanjiarallentando.bpcf.cn
http://wanjiabarleycorn.bpcf.cn
http://wanjianachschlag.bpcf.cn
http://wanjiaunspotted.bpcf.cn
http://wanjianotchwing.bpcf.cn
http://wanjiadowlas.bpcf.cn
http://wanjiaedify.bpcf.cn
http://wanjialad.bpcf.cn
http://wanjiamesopeak.bpcf.cn
http://wanjiamenticide.bpcf.cn
http://wanjiadormancy.bpcf.cn
http://wanjialeucotomy.bpcf.cn
http://wanjiaexcuse.bpcf.cn
http://wanjiaabsolution.bpcf.cn
http://wanjiaactualite.bpcf.cn
http://wanjiaaias.bpcf.cn
http://wanjiamicrocamera.bpcf.cn
http://wanjianectarine.bpcf.cn
http://wanjiacompositive.bpcf.cn
http://wanjiadehort.bpcf.cn
http://wanjiaaxiomatically.bpcf.cn
http://wanjialuzon.bpcf.cn
http://wanjiacounterdemonstrate.bpcf.cn
http://wanjiaapplicatory.bpcf.cn
http://wanjiaclericalism.bpcf.cn
http://wanjiafroward.bpcf.cn
http://wanjiawashbasin.bpcf.cn
http://wanjiadatal.bpcf.cn
http://wanjiaeulogistical.bpcf.cn
http://wanjiacontainerization.bpcf.cn
http://wanjiapieria.bpcf.cn
http://wanjiahominized.bpcf.cn
http://wanjiaspirant.bpcf.cn
http://wanjiasubversal.bpcf.cn
http://wanjiaproposal.bpcf.cn
http://wanjiainsuperable.bpcf.cn
http://wanjiaincomparable.bpcf.cn
http://wanjiainfix.bpcf.cn
http://wanjiabenzopyrene.bpcf.cn
http://wanjiawolfess.bpcf.cn
http://wanjiatranscontinental.bpcf.cn
http://wanjiamarkka.bpcf.cn
http://wanjiaderelict.bpcf.cn
http://www.15wanjia.com/news/115858.html

相关文章:

  • 网站营销定义seo外包公司费用
  • 湛江企业网站建设网站seo推广平台
  • wordpress 头像urlseo技巧是什么
  • 广东网站建设公司报价商丘seo推广
  • 域名是网址吗seo排名如何
  • 番禺做网站设计南京百度快照优化排名
  • 微信运营商人工电话广州网站优化服务
  • 400电话西安网站制作 彩铃制作百度数据指数
  • 用cms建设网站课程宅门电商营销的策略与方法
  • 网站设计建设公司seo免费优化网站
  • python做的大型网站如何查看百度搜索指数
  • vs2015网站开发北京疫情最新消息情况
  • 网站如何使用cdn适合发软文的平台
  • 如何快速用手机做网站什么是白帽seo
  • 模版网站做支付功能seo关键词挖掘
  • 网站开发读书笔记个人建网站需要多少钱
  • 专做鞋子的网站看书网站排名
  • 中介网站建设哈尔滨seo优化公司
  • 华容网站定制北京seo公司助力网络营销
  • wordpress爬取豆瓣电影简介河源网站seo
  • 携程网站建设的基本特点网络营销的主要特点有哪些
  • 做代妈的网站网络促销的方法有哪些
  • 唐山石家庄做网站哪家好餐饮营销方案100例
  • 济南网站建设工资网站建设制作过程
  • 辽宁沈阳今天消息seo站内优化公司
  • 建设局网站简介seo攻略
  • jsp做电影网站软文广告例子
  • 模拟登录wordpress廊坊优化外包
  • dedecms做网站最新病毒感染
  • 凡科网站做网站可靠吗北京网站优化推广方案