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

猜你喜欢

转载自blog.csdn.net/weixin_43189735/article/details/84180955