TA的每日心情 | 无聊 3 天前 |
---|
签到天数: 530 天 连续签到: 2 天 [LV.9]测试副司令
|
1测试积点
遍历页面,没有获取全部数据没有报错,获取了第一条数据,没有全部数据- <span style="font-weight: normal;">from selenium import webdriver
- from 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[2]/div/div[1]/div/div/div/div[1]/form/fieldset/div/div[2]/button').click()
- time.sleep(1)
-
-
- #人为移动driver
- driver.switch_to.window(driver.window_handles[1])
-
- 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[i].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[i].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[0].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[i].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[i].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>
-
复制代码
|
|