要点:1.利用datatime构建 日期,设定格式
2.利用selenium 登录账号,input等待需要输入的验证码
3.可以利用scrapy的Selector,替代beautifysoup 得到想要的标签
4.selenium的操作,选定筛选条件、模拟键盘的enter
5.使用try语句,错误时用logging提示错误,没问题就继续else里面的语句
6.保存csv文件的具体写法!!
#步骤:
'''
1.登录,进入 ishijian页面,返回源代码
3.设定 天使论
循环35个行业
设定 行业跟 天使轮
循环365天
设定 时间, 返回筛选后的页面
下面是具体代码:
import time,os,csv,logging from selenium import webdriver from selenium.myfox import myfox from scrapy import Selector from selenium.webdriver.common.keys import Keys class qimingpian(object): def __init__(self): self.phone_number = '1888888888' #登录手机 self.login_url = 'http://auth.qimingpian.com/finos.html' #登录网址 self.url='http://vip.qimingpian.com/#/finos/investment/ishijian'#操作网址 self.driver = myfox().work() #启动浏览器 self.times=self.alltime() #一年日期组成的list self.csv_file = os.getcwd() + '\\' + 'data.csv' #csv文件路径 def alltime(self): '''得到以今天为止近一年的日期组成的list''' import datetime dateend = datetime.date.today() datestart = dateend - datetime.timedelta(days=365) alltime = [] while datestart < dateend: alltime.append(datestart.strftime('%Y.%m.%d')) datestart += datetime.timedelta(days=1) return alltime ##['2017.06.10', '2017.06.11', '2017.06.12', '2017.06.13',.....] def qimingpian_login(self, url): '''登录网页,然后输入账户,点击短信登录''' self.driver.maximize_window() self.driver.get(url) self.driver.implicitly_wait(3) self.driver.find_element_by_xpath('//div[@class="fl tab-phone hand"]').click() user = self.driver.find_element_by_xpath('//*[@class="form-con dib phone-input"]') user.send_keys(self.phone_number) self.driver.find_element_by_xpath('//*[@id="code-btn"]').click() time.sleep(2) code = input('请输入短信验证那个码') pwd = self.driver.find_element_by_xpath('//*[@class="form-con code-input fl"]') pwd.send_keys(code) time.sleep(0.5) self.driver.find_element_by_xpath('//*[@id="phone-login"]').click() time.sleep(20) #return self.driver def login(self): '''这是最开始需要登录的步骤,返回的还是 ishijian 的页面的源代码''' print(