zoukankan      html  css  js  c++  java
  • python-webbrowser模块 浏览器操作

    python的webbrowser模块支持对浏览器进行一些操作,对于爬虫来说是比较基础的知识点

    1.主要有以下三个方法:

    webbrowser.open(url, new=0, autoraise=True)

    webbrowser.open_new(url)

    webbrowser.open_new_tab(url)

    import webbrowser as web
    web.open(‘http://www.baidu.com’,new=0,autoraise=True)     #new:0/1/2 0:同一浏览器窗口打开 1:打开浏览器新的窗口,2:打开浏览器窗口新的tab
                                                            #autoraise=True:窗口自动增长
    web.open_new(‘http://www.baidu.com’)
    web.open_new_tab(‘http://www.baidu.com’)

    2.指定浏览器对象打开

    web.get(name):获取打开的浏览器对象,name为空,则打开默认的浏览器,name为浏览器名称

    直接打开则会报错,需要注册浏览器对象

    web.register():注册浏览器类型

    import webbrowser as web
    chromepath = 'C:************GoogleChromeApplicationchrome.exe'            #  例如我的:C:************GoogleChromeApplicationchrome.exe  
    web.register('chrome', None, webbrowser.BackgroundBrowser(chromepath))  
    web.get('chrome').open_new_tab('www.baidu.com') 

     

  • 相关阅读:
    C语言指针和数组
    C语言malloc、calloc函数
    33、二叉树的后序遍历序列
    进程、线程、协程
    8、字符串转整数
    51、数组中的逆序对
    49、丑数
    19、正则表达式匹配
    32、从上到下打印二叉树
    leetcode5:最长回文子串
  • 原文地址:https://www.cnblogs.com/evablogs/p/7649502.html
Copyright © 2011-2022 走看看