splinter

Python: How to fill out form all at once with splinter/Browser?

江枫思渺然 提交于 2019-12-04 06:45:56
Currently, I’m filling out the form on a site with the following: browser.fill(‘form[firstname]’, ‘Mabel’) browser.fill(‘form[email]’, ‘hi@hi.com’) browser.select(‘form[color]’, ‘yellow’) But the form gets filled out the form sequentially, one after the other. Is there a way to fill out the form all at once? Thank you and will be sure to vote up and accept the answer! Browser has a method called: fill_form(field_values) It takes a dict parameter, with the field names, and the values, and it fills the form at once. So you'll use browser.fill_form(dict) instead of browser.fill(field, value) More

Splinter or Selenium: Can we get current html page after clicking a button?

有些话、适合烂在心里 提交于 2019-12-04 05:07:17
I'm trying to crawl the website " http://everydayhealth.com ". However, I found that the page will dynamically rendered. So, when I click the button "More", some new news will be shown. However, using splinter to click the button doesn't let "browser.html" automatically changes to the current html content. Is there a way to let it get newest html source, using either splinter or selenium? My code in splinter is as follows: import requests from bs4 import BeautifulSoup from splinter import Browser browser = Browser() browser.visit('http://everydayhealth.com') browser.click_link_by_text("More")

Manipulating browser (window) size using Splinter

做~自己de王妃 提交于 2019-12-04 03:32:32
I am trying to use the Firefox driver for Splinter to test some responsive design. Naturally, this requires me to resize the browser window. I can't find anything at all about browser resizing in the documentation . How can I do this? from splinter import Browser with Browser() as browser: # How do I set the browser size? Just do this: browser.driver.set_window_size(640, 480) The Splinter API doesn't seem to directly support this - or at least not yet. The generic API docs , as well as the docs for each specific browser's driver, currently make no mention of anything related to window size).

Unable to add a cookie using Selenium & Splinter

早过忘川 提交于 2019-12-03 22:16:17
问题 Per below, I'm not sure how to troubleshoot this pretty simple usage scenario. I have script (that I run about once a month) that functionally does the identical thing and which used to work as of a month ago. I'd appreciate any pointers on places to start looking into why this does not work. $ python3 Python 3.6.1 (default, Mar 23 2017, 16:49:06) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>>

Get href value in Splinter?

北城以北 提交于 2019-12-03 15:19:58
I would like to get href value from <a> element in Splinter. Is there any api method for that? If you are selecting elements using the find_by_* methods , instances returned by these are ElementList s . After you select the element you are interested in (most probably an ElementAPI instance), access the property like a dictionary: the_element['href'] #simplest possible working example demonstrating this in action import splinter b = splinter.Browser() b.visit("http://www.google.com") elems = b.find_by_tag("a") for e in elems: print(e["href"]) 来源: https://stackoverflow.com/questions/21816397

Python Splinter (SeleniumHQ) how to take a screenshot of many webpages? [Connection refused]

匿名 (未验证) 提交于 2019-12-03 03:03:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I want to take a screenshot of many webpages, I wrote this: from splinter . browser import Browser import urllib2 from urllib2 import URLError urls = [ 'http://ubuntu.com/' , 'http://xubuntu.org/' ] try : browser = Browser ( 'firefox' ) for i in range ( 0 , len ( urls )) : browser . visit ( urls [ i ]) if browser . status_code . is_success () : browser . driver . save_screenshot ( 'your_screenshot' + str ( i ) + '.png' ) browser . quit () except SystemError : print ( 'install firefox!' ) except urllib2 . URLError , e : print ( e )

splinter操作ie浏览器

匿名 (未验证) 提交于 2019-12-02 23:49:02
splinter 是在selenium上的封装,很多操作更方便,但是默认似乎不能直接操作ie,通过修改browser.py文件,splinter\driver\webdriver下增加ie.py文件,可以直接操作ie浏览器。 环境:py3.7,win7,实测基本操作没问题,点击、查找元素、选择切换frames等。 修改browser.py文件,添加两行: from splinter.driver.webdriver.ie import WebDriver as IeWebDriver #添加 from splinter.exceptions import DriverNotFoundError _DRIVERS = { "firefox": FirefoxWebDriver, "remote": RemoteWebDriver, "chrome": ChromeWebDriver, } splinter\driver\webdriver下增加ie.py,在chrome.py基础上修改 github链接:https://github.com/chengair/SplinterforIe

splinter

匿名 (未验证) 提交于 2019-12-02 23:34:01
模拟浏览器爬取信息 > #模拟chrome 浏览器打开网址 并进行爬取东西 from splinter import Browser b=Browser('浏览器名') #打开浏览器 #需要安装对应的驱动 > #访问网站的网址 b.visit('访问的网址') > #find_by_css()查询 click点击 b.find_by_css('body > div.register_layer > div.register_bg >a').click() > #输出文本 b.find_by_css('#container_jobList > ul > li:nth-child(1)').text # #切换窗口 #打开第二个窗口 二级页面 b.windows.current=b.windows[1] #指定当前操作窗口 b.windows[0].close_others() #关闭除了指定窗口外的其他窗口 b.find_by_css(’#page-con > input’).fill(5) #输入页码 b.find_by_css(’#page-con > span.go_jump’).click() #点击跳转 为了防止访问的时间太快,被发现,可加入time import time time.sleep(4) #4秒后运行 文章来源: https://blog.csdn.net

Python分布式爬虫打造搜索引擎Scrapy精讲

霸气de小男生 提交于 2019-12-01 17:57:51
快乐糖果屋 三十一 Python分布式爬虫打造搜索引擎Scrapy精讲—chrome谷歌浏览器无界面运行、scrapy-splash、splinter 1、chrome谷歌浏览器无界面运行 chrome谷歌浏览器无界面运行,主要运行在Linux系统,windows系统下不支持 chrome谷歌浏览器无界面运行需要一个模块,pyvirtualdisplay模块 需要先安装 pyvirtualdisplay模块 Display(visible=0, size=(800, 600))设置浏览器,visible=0表示不显示界面,size=(800, 600)表示浏览器尺寸 # -*- coding: utf-8 -*- import scrapy from scrapy.http import Request,FormRequest from selenium import webdriver # 导入selenium模块来操作浏览器软件 from scrapy.xlib.pydispatch import dispatcher # 信号分发器 from scrapy import signals # 信号 class PachSpider(scrapy.Spider): #定义爬虫类,必须继承scrapy.Spider name = 'pach' #设置爬虫名称 allowed

Unable to add a cookie using Selenium & Splinter

走远了吗. 提交于 2019-12-01 00:39:21
Per below, I'm not sure how to troubleshoot this pretty simple usage scenario. I have script (that I run about once a month) that functionally does the identical thing and which used to work as of a month ago. I'd appreciate any pointers on places to start looking into why this does not work. $ python3 Python 3.6.1 (default, Mar 23 2017, 16:49:06) [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from selenium import webdriver >>> from splinter import Browser >>> chrome_options = webdriver