selenium实战脚本集——新浪微博发送QQ每日焦点(火狐)

selenium实战脚本集(1)——新浪微博发送QQ每日焦点,乙醇用谷歌实现的,下边是用火狐实现的。

代码如下:

# coding = utf-8

from selenium import webdriver

import time



profiles = webdriver.FirefoxProfile("C:/Documents and Settings/Administrator/Application Data/Mozilla/Firefox/Profiles/rhw9fq7m.default")

driver = webdriver.Firefox(profiles)

driver.get("http://www.qq.com")

today = driver.find_element_by_css_selector("#todaytop a")

content = today.text

url = today.get_attribute("href")

print content.encode("utf-8")

print url



driver.get("http://www.weibo.com")

time.sleep(5)

driver.find_element_by_css_selector("textarea.W_input").send_keys(content+url)

driver.find_element_by_css_selector("a.W_btn_a.btn_30px").click()

time.sleep(5)

driver.close()

常见错误

xp和win7下面chrome 的profile路径是不一样的

  • Windows XP:%userprofile%\Local Settings\Application Data\Mozilla\Firefox\Profiles\或%userprofile%\Application Data\Mozilla\Firefox\Profiles\
  • Windows Vista/Windows 7/Windows 8:%localappdata%\Mozilla\Firefox\Profiles\

你可能感兴趣的:(selenium)