#!/usr/bin/python
#encoding=utf-8
__author__ = 'Administrator'
from bs4 import BeautifulSoup
import selenium
import sys
import urllib
import requests
import time
import re
if __name__ == "__main__":
import os
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0'}
chromedriver = "/home/henson/Documents/pycharm/webdriver/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.get('http://qikan.cqvip.com/writer/writersearch.aspx?from=writer_writersearch&key=U%3D%E5%A4%A7%E6%B0%94%E6%B1%A1%E6%9F%93')
currentURL=driver.current_url
time.sleep(2)
#currentURL=driver.current_url
urlList=[]
localDir = '/home/henson/Downloads/paper'
# bbc=driver.find_element_by_xpath("//*[@id='body']/div/div[3]/div[3]/dl[1]/dt/a[@class='title btnTitle']").click()
# print(bbc)
k=1
for j in range (1,2):
driver.find_element_by_xpath("//*[@id='body']/div/div[3]/div[3]/dl["+str(j)+"]/dt/a[@class='title btnTitle']").click()
time.sleep(6)
currentURL = driver.current_url
# print(currentURL)
# print("NO."+str(j)+"页")
author= driver.find_element_by_xpath(
"//*[@id='body']/div[1]/dl/dt/h1").text
cites = driver.find_element_by_xpath(
"//*[@id=’body‘]/div[1]/dl/dd[1]").text
mechanism = driver.find_element_by_xpath(
"//*[@id=’body‘]/div[1]/dl/dd[3]/span").text
theme = driver.find_element_by_xpath("//*[@id='body']/div[1]/dl/dd[4]").text
print(author)
print(cites)
print(mechanism)
print(theme)
"""
分开获取
j(1-21) : k=1 , k=11
j(19-n) : k=12, k=10
"""
取的xpath出不来的要么是自己的问题,没有耐心细心,,要么是加载时间不够。