MAC OS + Python3 + SeleniumWebdriver

安装SeleniumWebdriver

点击打开 Pipy SeleniumWebdriver地址

pip install selenium

安装ChromeDriver

点击打开ChromeDriver Taobao 镜像

brew install wget --with-libressl
wget https://npm.taobao.org/mirrors/chromedriver/71.0.3578.33/chromedriver_mac64.zip
unzip chromedriver_mac64.zip
sudo mv chromedriver /usr/local/bin/chromedriver
sudo chmod u+x,o+x  /usr/local/bin/chromedriver
chromedriver --version

安装FireFox Geckodriver

点击打开FireFox Geckodriver @ Github

brew install geckodriver
geckodriver

vi python_org_search.py

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.implicitly_wait(10)
driver.get("http://roll.auto.qq.com/")
# assert "百度一下" in driver.title
elem = driver.find_elements(By.XPATH, "//div[@id='artContainer']//a")
for target_list in elem:
  print(target_list.text)
  print(target_list.get_attribute("href"))

driver.close()

运行结果:

MacBook-Air-2: XXX $ python python_org_search.py 
[腾讯行情] 传祺GA3S视界最高优惠1.38万元
http://auto.qq.com/a/20181121/008593.htm
[腾讯行情] 传祺GS5 Super最高优惠1.50万元
http://auto.qq.com/a/20181121/008548.htm
[腾讯行情] 传祺GA5 PHEV最高优惠0.80万元
http://auto.qq.com/a/20181121/008547.htm
[腾讯行情]长春 迈腾最高优惠4.80万元
http://auto.qq.com/a/20181121/008478.htm
[腾讯行情]长春 高尔夫·嘉旅最高优惠3.20万元
http://auto.qq.com/a/20181121/008475.htm
售12.99万元起 别克英朗/阅朗新增车型上市
http://auto.qq.com/a/20181121/008624.htm
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在Mac OS上安装SeleniumWebdriver的步骤: 1. 安装Python Selenium是使用Python编写的,因此需要首先安装Python。可以从Python官方网站下载并安装最新版本的Python。 2. 安装pip pip是Python的包管理器,可以用来安装Python模块。在终端中输入以下命令来安装pip: ``` sudo easy_install pip ``` 3. 安装Selenium 在终端中输入以下命令来安装Selenium: ``` pip install selenium ``` 4. 下载Webdriver Webdriver是用来控制浏览器的工具,需要下载对应浏览器的Webdriver。例如,如果要使用Chrome浏览器,则需要下载Chrome的Webdriver。可以从以下链接下载对应的Webdriver: Chrome:https://sites.google.com/a/chromium.org/chromedriver/downloads Firefox:https://github.com/mozilla/geckodriver/releases Safari:https://webkit.org/blog/6900/webdriver-support-in-safari-10/ 5. 配置Webdriver路径 将下载的Webdriver解压缩,并将其路径添加到系统PATH环境变量中。可以通过编辑.bash_profile文件来实现: ``` nano ~/.bash_profile ``` 在文件末尾添加以下行: ``` export PATH=$PATH:/path/to/webdriver ``` 其中,/path/to/webdriver需要替换为实际的Webdriver路径。 保存并退出文件后,执行以下命令以重新加载.bash_profile文件: ``` source ~/.bash_profile ``` 现在就可以在Python脚本中使用SeleniumWebdriver来控制浏览器了。例如,以下代码片段展示了如何使用Chrome浏览器: ```python from selenium import webdriver # 创建Chrome浏览器实例 driver = webdriver.Chrome() # 打开网页 driver.get("https://www.google.com") # 关闭浏览器 driver.quit() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值