# coding:utf-8
from selenium import webdriver
import time
import random
driver=webdriver.Firefox()
driver.get("https://www.baidu.com")
time.sleep(10)
#搜索字符
driver.find_element_by_id("kw").send_keys(u"网易")
driver.find_element_by_id("kw").submit()
time.sleep(10)
#定位到搜索结果
s=driver.find_elements_by_css_selector("h3.t>a")
#打印定位到的url
for i in s:
print(i.get_attribute('href'))
#设置随机值
t=random.randint(0,9)
print(t)
#随机取一个值获取其url并打开
b = s[t].get_attribute('href')
print(b)
driver.get(b)
#随机打开其中一条url
#s[t].click()