Python 需要帮助爬过多个搜索结果页面吗

Python 需要帮助爬过多个搜索结果页面吗,python,selenium,web,web-crawler,Python,Selenium,Web,Web Crawler,我很难让“def get_next_page”浏览整个搜索结果页面。到目前为止,它只上到第二页 此代码的主要功能是从所有页面获取一般信息(公司、产品、位置等) import unittest from selenium import webdriver from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as

我很难让“def get_next_page”浏览整个搜索结果页面。到目前为止,它只上到第二页

此代码的主要功能是从所有页面获取一般信息(公司、产品、位置等)

 import unittest
 from selenium import webdriver
 from selenium.webdriver.support.wait import WebDriverWait
 from selenium.webdriver.support import expected_conditions as EC
 from selenium.webdriver.common.by import By
 from selenium.webdriver.common.keys import Keys
 from bs4 import BeautifulSoup
 import time
 import re

def openPage():
   driver = webdriver.Firefox()
   driver.get("http://www.made-in-china.com/companysearch.do?subaction=hunt&order=0&style=b&code=0&word=aerator")
   elem = WebDriverWait(driver,60).until(EC.presence_of_element_located((By.CLASS_NAME,'search-list')))               
   analyzePage(driver)
   get_next_page(driver)


def analyzePage(driver):   
   center = driver.find_element_by_xpath('/html/body/div[6]/div[1]/div[1]/div/div[4]') 
   companyBox=center.find_elements_by_class_name('list-node')  

for items in companyBox:   

    companyName = items.find_element_by_tag_name('h2').text.encode('utf-8')                          
    print 'companyName: ' ,companyName 

    companyLink= items.find_element_by_tag_name('h2').find_element_by_tag_name('a').get_attribute('href')
    print 'companyLink: ', companyLink 

    companyInfo=items.find_elements_by_tag_name('tr')     
    companyType=companyInfo[0].text.encode('utf-8')
    print companyType

    companyProduct=companyInfo[1].text.encode('utf-8')
    print companyProduct

def get_next_page(driver):
   page = driver.find_element_by_xpath ("/html/body/div[6]/div[1]/div[1]/div/div[6]/div[1]/div")
   start_link = page.find_elements_by_tag_name('a')
   for item in start_link:
     href = item.get_attribute('href')
     print href
     print"==========================================================="
     driver.execute_script(href)
     analyzePage(driver) 
return driver       


if __name__ == "__main__":
   openPage()
事先非常感谢

编辑:还是很困惑,有什么建议吗


编辑:再次凹凸。

您可以编写一个函数,单击按钮/超链接转到下一页。然后从该页面获取信息

for i in range(len):
    if i>0 :
        driver.find_element_by_link_text('Next').click()
    time.sleep(5)
    #get the information here

谢谢,但结果仍然没有什么不同。我第一次尝试将它添加到“get_next_page”(获取下一页)下,没有任何改变。然后,我将“get_next_page”替换为您的,包括更改,并始终返回一个错误:TypeError:range()应为integer end参数,get builtin_函数或_方法。确保驱动程序获得正确的链接并单击它可能很有用。你会看到firefox打开,点击事件进入下一页。我现在很忙,但今天晚些时候我会检查你的代码…很抱歉回复太晚,我再次检查了链接,它们工作正常。考虑只是手动将每个链接放入。