昊天SEO

selenium 采集ajax的网页,怎么采集

#coding=utf-8
from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
import unittest
import time
import sys,re,string
reload(sys)
sys.setdefaultencoding('utf8')
dd=webdriver.Chrome()
dd.get('http://www.toutiao.com/search/?keyword=%E5%81%A5%E8%BA%AB')

# ActionChains(dd).move_by_offset(5000,0).perform()
i=0
while i
#coding=utf-8
from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
import unittest
import time
import sys,re,string
reload(sys)
sys.setdefaultencoding('utf8')
dd=webdriver.Chrome()
dd.get('http://www.toutiao.com/search/?keyword=%E5%81%A5%E8%BA%AB')

# ActionChains(dd).move_by_offset(5000,0).perform()
i=0
while i<20:
 dd.execute_script("window.scrollTo(0, document.body.scrollHeight);") #
 i+=1
 time.sleep(0.5)


# ActionChains(dd).move_by_offset(x2,0).perform()
for i in dd.find_elements_by_xpath('//*[@id="pagelet-feedlist"]/ul/li/div[1]/p'):
 print i.text

本文地址官网    新乡网站建设,seo

本文网址:http://www.168seo.cn/selenium/2479.html
分享到:更多 ()
a