# -*- coding:UTF-8 -*-
#!/usr/bin/python

from bs4 import BeautifulSoup
from selenium import webdriver

maxChapter = 3
bookUrl = 'http://big5.quanben.io/n/wodepiaoliangnushangsi/list.html'

browser = webdriver.Firefox()
browser.implicitly_wait(30)  # 隐性等待，最长等30秒
browser.maximize_window()  # 最大化

def clickLink(text):
   link = browser.find_element_by_link_text(text)
   link.click()

   soup = BeautifulSoup(browser.page_source, 'html.parser')
   p = soup.find_all('p')
#   p = browser.find_elements_by_css_selector('p')

   for s in p:
      print(s.text)

def clickChapter(url):
   browser.get(url)
   print(browser.title)
   print(browser.current_url)

#   soup = BeautifulSoup(browser.page_source, 'html.parser')
#   li = soup.find_all('li')
   li = browser.find_elements_by_css_selector('li')

   clickLink(li[5].text)

"""
   for l in li[:maxChapter]:
      clickLink(l.text)
      break
"""

clickChapter(bookUrl)

print(browser.current_url)
input('Press enter to continue......')

browser.quit()
