webdriver

python 使用selenium模块实现自动搜索百度百科词条(模拟人工搜索)

久未见 提交于 2020-02-25 01:56:05
目标: 模拟人工搜索百度百科词条,爬取相关信息,自动删除上一个关键词,输入新关键词,继续搜索,直到循环结束。 代码: from selenium import webdriver from selenium.webdriver.common.keys import Keys import time from bs4 import BeautifulSoup univs = ['清华大学', '不知道大学', '北京大学'] AllUnivInfolist = [] browser = webdriver.Firefox() # 创建一个浏览器对象,这里还可以使用chrome等浏览器 try: browser.get('https://baike.baidu.com/') # 打开百科 for univ in univs: browser.find_element_by_id('query').send_keys(univ) # 找到输入框输入字段 time.sleep(3) browser.find_element_by_id('search').send_keys(Keys.ENTER) # 找到搜索按钮模拟点击 time.sleep(3) html = browser.page_source # 获取html页面 soup = BeautifulSoup(html, 'html

Timeout expired waiting for async script on IE 9

雨燕双飞 提交于 2020-02-24 05:49:08
问题 I'm trying to run some tests (using Protractor) on Internet Explorer 9 - and each test that contains " driver.executeScript " gives an error : Timeout expired waiting for async script (WARNING: The server did not provide any stacktrace information). The other tests work very well. It seems that IE doesn't understand the timeout limit that I add at the end of function (20000 ms) - Timeout expires after ~11 seconds. Is there any WebdriverJS code line to make it wait for async execution? All

Python爬虫 使用Selenium爬取腾讯招聘信息

有些话、适合烂在心里 提交于 2020-02-24 05:02:21
使用Selenium爬取腾讯招聘信息,并保存excel 代码比较简单,直接上源码 from selenium import webdriver from selenium . webdriver . support . wait import WebDriverWait from selenium . webdriver . support import expected_conditions as EC from selenium . webdriver . common . by import By from lxml import etree import xlwt class Tencent ( object ) : def __init__ ( self , url ) : self . url = url self . driver = webdriver . Chrome ( ) self . data_list = [ ] self . main ( ) # 返回页面内容 def get_content_by_selenium ( self , url ) : self . driver . get ( url ) # 显示等待 直到div[@class="correlation-degree"]'加载出来 wait = WebDriverWait ( self .

BILIBILI之滑块验证

三世轮回 提交于 2020-02-23 08:43:40
bilibili的滑动验证码图片比较好玩,和前一篇不大一样。 采用canvas方法,分析发现只找到一个图片,不过,可以通过设置display截图方式获得2张图(完整图片,带缺口的图片),取得图片后接下来的方式和前一篇一样,偏移位置参数存在差异,需要自行调试。完整代码如下 #!/usr/bin/env python # encoding: utf-8 #@author: jack #@contact: 935650354@qq.com #@site: https://www.cnblogs.com/jackzz import re from time import sleep from selenium import webdriver import random import requests from PIL import Image from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from io import BytesIO from selenium.webdriver.common.action

How to Wait for an Alert in Selenium WebDriver with C#?

无人久伴 提交于 2020-02-23 08:26:25
问题 How can i set Selenium WebDriver to Wait for an Alert before accepting it instead of Thread.Sleep? As website, sometimes loads very slowly or sometimes fast. Thanks 回答1: You should apply webdriver wait for an alert to be present properly. new WebDriverWait(driver, TimeSpan.FromSeconds(15)); wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.AlertIsPresent()); OR write a boolean function to check alert present and use it for wait bool IsAlertShown(WebDriver driver) { try { driver

一起学爬虫——使用selenium和pyquery爬取京东商品列表

淺唱寂寞╮ 提交于 2020-02-22 16:37:45
layout: article title: 一起学爬虫——使用selenium和pyquery爬取京东商品列表 mathjax: true --- 今天一起学起使用selenium和pyquery爬取京东的商品列表。本文的所有代码是在pycharm IDE中完成的,操作系统window 10。 1、准备工作 安装pyquery和selenium类库。依次点击file->settings,会弹出如下的界面: 然后依次点击:project->project Interpreter->"+",,如上图的红色框所示。然后会弹出下面的界面: 输入selenium,在结果列表中选中“selenium”,点击“install package”按钮安装selenium类库。pyquery也是一样的安装方法。 安装chrome和chrome driver插件。chrome dirver插件下载地址: http://npm.taobao.org/mirrors/chromedriver/ 。 切记chrome和chrome dirver的版本要一致。我的chrome版本是70,对应chrome driver是2.44,2.43,2.42。 下载chrome driver解压后,将exe文件拷贝到pycharm开发空间的Scripts文件夹中: 2、分析要爬取的页面

爬取北京市政百姓信件内容

坚强是说给别人听的谎言 提交于 2020-02-22 12:05:58
问题: 换页url不边,Ajax加载,于是进行抓包: 可是发现换页的时候Request URL也不变(看很多类似教程都是找url变化规律) 这时候我选择使用selenium和Chrome配合,模拟浏览器输入页数获得网页: 源代码: from lxml import etreeimport requestsimport csvfrom selenium import webdriverimport timeimport osfrom selenium.webdriver.chrome.webdriver import WebDriver#创建csvoutPath = 'D://xinfang_data.csv'if (os.path.exists(outPath)): os.remove(outPath)fp = open(outPath, 'wt', newline='', encoding='utf-8') # 创建csvwriter = csv.writer(fp)writer.writerow(('kind', 'time', 'processingDepartment', 'content'))#请求头headers = { 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36

Automagica小试

|▌冷眼眸甩不掉的悲伤 提交于 2020-02-22 04:51:59
  近期工作中接触RPA(Robotic Process Automation,即机器人流程自动化)方向的项目,在做技术预研中,接触了 UiBot 和 Automagica 这两款流程自动化的组件。其中 UiBot 是一款成熟的软件产品,安装其平台后,可以直接按用户的业务场景,通过绘制流程图+配置动作和参数的方式,定制自动化流程场景。当然它也提供了Python、C/C++、Lua、.Net等多种编程语言的扩展接口,支持更灵活的编程式开发。它入门门槛较低,直接通过点击就可以实现诸如浏览器数据抓取、文档批量操作等一般的业务场景,非工程人员也可以快速上手使用。这里我们对UiBot不做深入介绍,而来了解一下 Automagica 这个平台。   Automagica 是一个开源智能机器人流程自动化(SRPA,Smart Robotic Process Automation)平台,借助 Automagica 的python 函数库,可以通过简单程序脚本实现打开各种应用程序并对应用进行操作的功能,使自动化跨平台流程变得轻而易举。   首先,Automagica 需要 Python 3.7 环境,官方支持 Windows 10 平台,Linux 和 Mac 目前官方还不支持。我这里使用的实验环境是Python 3.7.3,操作系统为 Win10系统。没有安装Python的请自行去官网下载

python网络爬虫之图片链家在技术.seleninum和PhantonJS

ⅰ亾dé卋堺 提交于 2020-02-22 00:49:26
一.什么是图片懒加载? 案例分析:抓取站长素材http://sc.chinaz.com/中的图片数据 #!/usr/bin/env python # -*- coding:utf-8 -*- import requests from lxml import etree if __name__ == "__main__": url = 'http://sc.chinaz.com/tupian/gudianmeinvtupian.html' headers = { 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36', } #获取页面文本数据 response = requests.get(url=url,headers=headers) response.encoding = 'utf-8' page_text = response.text #解析页面数据(获取页面中的图片链接) #创建etree对象 tree = etree.HTML(page_text) div_list = tree.xpath('//div[@id="container"]/div')

How to remove Scrollbar in ChromeDriver, how to change http-agent?

ⅰ亾dé卋堺 提交于 2020-02-21 13:17:18
问题 I use IWebDriver driver = new ChromeDriver(options) in C# When I take .GetScreenshot(); , often see scrollbar, is there a way to remove it? 2nd question, how to mock/change http_agent in ChromeDriver? 回答1: Scrollbar issue: Try using Chrome switches when starting webdriver. See http://peter.sh/experiments/chromium-command-line-switches/ or chrome://flags/ in Chrome. You can also make Chromedriver open the url in a popup without scrollbars. You can do this using some Javascript. Or you could