TA的每日心情 | 郁闷 2017-3-1 13:43 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]测试小兵
|
唯品会打不开
页面结构不清楚 看看是不是可以利用属性来找
driver.find_elements_by_css_selector(st1)[i].get_attribute("xxxx")
下面是一个
# coding=utf-8
from selenium import webdriver
from datetime import *
import requests, time
import re
import time
def getdate():
st = "brind_item"
elem = driver.find_elements_by_css_selector(st)
st1 = "xxxx"
for st in elem:
r = st.get_attribute("innerHTML")
link = r'<a href="/list.vip.com/.*?>(.*?)</a>'
return link
def Login(username,password):
try:
driver.get("login page link")
time.sleep(3)
driver.find_element_by_id("user_login").clear()
driver.find_element_by_id("user_login").send_keys(username)
driver.find_element_by_id("user_password").clear()
driver.find_element_by_id("user_password").send_keys(password)
driver.find_element_by_name('commit').click()
time.sleep(3)
print driver.current_url
print u'登陆成功...'
except Exception,e:
print "Error: ",e
finally:
print u'End Login!\n\n'
if __name__ == '__main__':
driver = webdriver.PhantomJS() #使用PhantomJS作为模拟浏览器
#定义变量
username = 'xxxx' #输入你的用户名
password = 'xxx' #输入你的密码
#登录
Login(username,password) #登陆
print driver.current_url #验证当前链接地址
#链接获取
url1 = ‘your link’
time.sleep(3)
driver.get(url1)
link = getdate()
driver.get(link)
driver.close()
|
|