盖得化工网——翻页测试---页码框输入页码

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

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

关键语句

browser=webdriver.Firefox()
browser.maximize_window() # 浏览器全屏显示
browser.get(list_pages_hubei[0])
page_elem=browser.find_element_by_name("PageNum")
browser.find_element_by_name("PageNum").clear()  #清除输入文本框的文字
page_elem.send_keys("3")   #输入进入第三页
#page_elem.send_keys("3")
page_elem.send_keys(Keys.RETURN)
browser.maximize_window() # 浏览器全屏显示 browser.get(list_pages_hubei[0]) page_elem=browser.find_element_by_name("PageNum") browser.find_element_by_name("PageNum").clear() #清除输入文本框的文字 page_elem.send_keys("3") #输入进入第三页 #page_elem.send_keys("3") page_elem.send_keys(Keys.RETURN)

# -*- 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.maximize_window() # 浏览器全屏显示
browser.get(list_pages_hubei[0])
page_elem=browser.find_element_by_name("PageNum")
browser.find_element_by_name("PageNum").clear()  #清除输入文本框的文字
page_elem.send_keys("3")   #输入进入第三页
#page_elem.send_keys("3")
page_elem.send_keys(Keys.RETURN)

'''
for page in list_pages_hubei[0:10]:
    browser.get(page)
    links_list=Get_corporation_site()
    list_corporation_link.append(links_list)
'''    


    
#测试速度太慢,主要是反复调用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/']]

'''

  

原文地址:https://www.cnblogs.com/webRobot/p/5476550.html