zoukankan      html  css  js  c++  java
  • 盖得化工--selenium翻页测试

    Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门

    https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6EmUbbW&id=564564604865

    以下结果还是费时,尝试reques4,bs4模块 

    # -*- coding: utf-8 -*-
    """
    Created on Mon May  9 09:14:32 2016
    
    @author: Administrator
    """
    import requests,bs4,csv,time,selenium,random
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    
    site_hubei="http://china.guidechem.com/suppliers/list_catid-21_area-%E6%B9%96%E5%8C%97"
    pages_hubei=31
    #所有公司的链接网址_存储列表
    list_corporation_link=[]
    
    def Get_sites(site,pages):
        list_pages=[]
        for page in range(1,pages+1):
            thePage=site+"-"+"p"+str(page)+".html"
            list_pages.append(thePage)
        
        return list_pages
        
    #采集一页所有公司的二级网址
    def Get_corporation_site():
        elems=browser.find_elements_by_class_name("dblue")
        links_list=[i.get_attribute("href") for i in elems]
        return links_list 
        
    
    #构造所有湖北页面网址    
    list_pages_hubei=Get_sites(site_hubei,pages_hubei)
    #打开浏览器
    browser=webdriver.Firefox()
    #获取首页
    browser.get(list_pages_hubei[0])
    
    
    #测试获取前十页公司的二级网址
    for i in range(1,10):
        links_list=Get_corporation_site()
        list_corporation_link.append(links_list)
        #翻下一页
        page_elem=browser.find_element_by_name("PageNum")
        browser.find_element_by_name("PageNum").clear()  #清除输入文本框的文字
        pageNum=str(i+1)
        page_elem.send_keys(pageNum)   #输入进入第三页
        page_elem.send_keys(Keys.RETURN)
    
    
    
        
    #测试速度太慢,主要是反复调用browser.get(page)    
    '''
    [['http://show.guidechem.com/hbsthcsales/',
      'http://show.guidechem.com/whdinghuichem/',
      'http://show.guidechem.com/hbeixys2001/',
      'http://show.guidechem.com/jusheng/',
      'http://show.guidechem.com/yongnuopharm/',
      'http://show.guidechem.com/gameboy0820/',
      'http://show.guidechem.com/whhxk/',
      'http://show.guidechem.com/zhuoxinghy/',
      'http://show.guidechem.com/nrcaocao/',
      'http://show.guidechem.com/hbxyhhgwy/',
      'http://show.guidechem.com/jushengkeji/',
      'http://show.guidechem.com/jushengchem4/',
      'http://show.guidechem.com/eva1210/',
      'http://show.guidechem.com/whdhwy/',
      'http://show.guidechem.com/chenjinping2014/',
      'http://show.guidechem.com/hbjltchem/',
      'http://show.guidechem.com/jlt7796/',
      'http://show.guidechem.com/saichuang123/',
      'http://show.guidechem.com/apidky/',
      'http://show.guidechem.com/finetechwh/'],
     ['http://show.guidechem.com/csw288/',
      'http://show.guidechem.com/cuizhiying123/',
      'http://show.guidechem.com/sjpxkj/',
    ...........  
      ttp://show.guidechem.com/hengshuochem/',
      'http://show.guidechem.com/DSHKJYXGS/',
      'http://show.guidechem.com/HUBEIBOKAI/',
      'http://show.guidechem.com/xiangdetech/']]
    
    '''
    

      

  • 相关阅读:
    正则表达式简介
    PHP中简单的页面缓冲技术
    PHP 程序加速探索
    PHP中通过Web执行C/C++应用程序
    PHP实现聊天室的主动更新与被动更新
    php中Cookie及其使用
    Linux 下 PHP 连接 MS SQLServer 的办法
    网站加速 PHP 缓冲的免费实现方法
    Spark Streaming中的基本操作函数实例
    Scala中的s函数
  • 原文地址:https://www.cnblogs.com/webRobot/p/5476639.html
Copyright © 2011-2022 走看看