selenium批量诚信通会员,重复一条数据
遍历页面,没有获取全部数据没有报错,获取了第一条数据,没有全部数据<span style="font-weight: normal;">from selenium import webdriverfrom selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
import time
import pandas as pd
driver = webdriver.Chrome()
#发送请求
driver.get("https://sale.1688.com/factory/home.html")
wait = WebDriverWait(driver,5)
#重要:暂停1分钟进行预登陆,此处填写账号密码及验证
time.sleep(60)
driver.find_element(By.XPATH,'//*[@id="home-header-searchbox"]').send_keys('诚信通')
driver.find_element(By.XPATH,'//*[@id="root"]/div/div/div/div/div/div/div/form/fieldset/div/div/button').click()
time.sleep(1)
#人为移动driver
driver.switch_to.window(driver.window_handles)
name = []
keeptime = []
nodes =driver.find_elements(By.CSS_SELECTOR,'#app > div > div.space-company-offer-list-temp > div.offerlist > div')
for i in range(0,len(nodes),1):
name.append(nodes.find_element(By.CSS_SELECTOR,'#app > div > div.space-company-offer-list-temp > div.offerlist > div > div:nth-child(1) > a > div.left-container > div.main-content > div.title-container > div.title').text)
keeptime.append(nodes.find_element(By.CSS_SELECTOR,'#app > div > div.space-company-offer-list-temp > div.offerlist > div > div:nth-child(1) > a > div.left-container > div.main-content > div.desc-container > div.identity-container > div.credit-tag.identity-tag').text)
for page in range(3):
try:
print(page)
# 定位下一页按钮
nextpage_button = driver.find_element(By.LINK_TEXT,'下一页')
#点击按键
driver.execute_script("arguments.click();", nextpage_button)
wait = WebDriverWait(driver,5)
nodes1 =driver.find_elements(By.CSS_SELECTOR,'#app > div > div.space-company-offer-list-temp > div.offerlist > div')
for i in range(0,len(nodes1),1):
name.append(nodes.find_element(By.CSS_SELECTOR,'#app > div > div.space-company-offer-list-temp > div.offerlist > div > div:nth-child(1) > a > div.left-container > div.main-content > div.title-container > div.title').text)
keeptime.append(nodes.find_element(By.CSS_SELECTOR,'#app > div > div.space-company-offer-list-temp > div.offerlist > div > div:nth-child(1) > a > div.left-container > div.main-content > div.desc-container > div.identity-container > div.credit-tag.identity-tag').text)
except:
pass
'''保存数据'''
data = pd.DataFrame({'诚信通会员名称':name,'诚信通开通':keeptime})
data.to_excel("weibo.xlsx")</span>
依次断电进行
页:
[1]