关于python中 selenium模块问题,新手看了好几天 实在解决不了,请求各路大神帮助 感谢!

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time

# 选择登录账户
user = "川国"
# 待统计任务对应分享链接
share_link = "https://wss.pet/s/3wlx4vq6208"

# 各用户登录信息(账号密码)
user_info = {
                "川国":['17724607375', 'panqi559']
            }
login_number = user_info[user][0]
login_password = user_info[user][1]

#不嫌麻烦可以像这样手动添加成员(一劳永逸)
name_list = {
           '豪总':0, '代伟':0, '肖时':0, '请贵司':0, '太少':0,
           '大波':0, '阿沙文':0, '硝站':0, '蒙城':0, '大炜':0 }

# import pandas as pd
# import numpy as np
# name_list = {}
# data = pd.read_excel("class_data.xlsx")
# data = data.iloc[2:,0]
# data = data.to_numpy()
# for i in range(len(data)):
#     name_list[str(data[i])] = 0;



# import urllib
# def asKURL(url):
#     head = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"}
#
#     request = urllib.request.Request(url,headers=head)
#     html = ""
#     try:
#          response = urllib.request.urlopen(request)
#          html = response.read().decode("utf-8")
#          print(html)
#     except urllib.error.URLError as e:
#         if hasattr(e,"code"):
#             print(e.code)
#         if hasattr(e.reason):
#             print(e.reason)
#     return html




chrome_options = Options()
chrome_options.add_argument("--headless")

driver = webdriver.Chrome(options=chrome_options)
driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(5)

print("Entering the website...")
url = "https://www.wenshushu.cn/signin"
driver.get(url)
time.sleep(2)

print("Inputing login info...")
driver.find_element_by_xpath("//div[@id='page_content']/div/div/div/div/ul/li[2]").click()
driver.find_element_by_xpath("//input[@type='text']").click()
driver.find_element_by_xpath("//input[@type='text']").clear()
driver.find_element_by_xpath("//input[@type='text']").send_keys(login_number)
driver.find_element_by_xpath("//input[@type='password']").click()
driver.find_element_by_xpath("//input[@type='password']").clear()
driver.find_element_by_xpath("//input[@type='password']").send_keys(login_password)
driver.find_element_by_xpath("//div[@id='page_content']/div/div/div/div[2]/div/div/button/span").click()
time.sleep(2)

print("Locating to the task...")
url = "https://www.wenshushu.cn/f/" + str(share_link[18:])
driver.get(url)

print("Checking submit info...")
time.sleep(3)
page_info = driver.find_elements_by_css_selector("[class='g-upload_user']")
for i in range(len(page_info)):
    name_list[page_info[i].get_attribute('innerText')] = 1
    print(page_info[i].get_attribute('innerText'))

print("Writing detailed list...")
print("unsubmit list:\n")
for name in name_list.keys():
    if(name_list[name] == 0):
        print(name)
print("\nsubmit list:\n")
for name in name_list.keys():
    if(name_list[name] == 1):
        print(name)
driver.close()

print("Check Finished!")

 

 

报错如下:

Traceback (most recent call last):
  File "C:/Users/Administrator/Desktop/checkkusi/shouji0000.py", line 68, in <module>
    driver.find_element_by_xpath("//div[@id='page_content']/div/div/div/div/ul/li[2]").click()
  File "D:\pythohuanjingzujian\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
  File "D:\pythohuanjingzujian\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
    'value': value})['value']
  File "D:\pythohuanjingzujian\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "D:\pythohuanjingzujian\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)

错误信息:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@id='page_content']/div/div/div/div/ul/li[2]"}
  (Session info: chrome=83.0.4103.14)

查看全部
buzzysun9
爱新觉罗·卜
2020/11/05 22:25
  • python
  • 数据挖掘
  • 点赞
  • 收藏
  • 回答
    私信

1个回复