使用python.text方法获取非类型

使用python.text方法获取非类型,python,selenium,web-crawler,nonetype,Python,Selenium,Web Crawler,Nonetype,我正在尝试根据列表的数量(TotalistNum)计算要运行的for循环的数量 它似乎在返回Nonetype,而实际上它应该返回text或int 网站: 代码如下 for prefectureValue in prefectureValueStorage: driver.get( f"https://stamprally.org/?search_keywords&search_keywords_operator=and&search_cat1={

我正在尝试根据列表的数量(TotalistNum)计算要运行的for循环的数量

它似乎在返回Nonetype,而实际上它应该返回text或int

网站:

代码如下

for prefectureValue in prefectureValueStorage:
    driver.get(
        f"https://stamprally.org/?search_keywords&search_keywords_operator=and&search_cat1={prefectureValue}&search_cat2=0")
    # Calculate How Many Times To Run Page Loop
    totalListNum = driver.find_element_by_css_selector(
        'div.page_navi2.clearfix>p').get_attribute('text')
    totalListNum.text.split("件中")
    if totalListNum[0] % 10 != 0:
        pageLoopCount = math.ceil(totalListNum[0])
    else:
        continue
    currentpage = 0
    while currentpage < pageLoopCount:
        currentpage += 1
        print(currentpage)
对于辖区值存储中的辖区值:
司机,快(
f“https://stamprally.org/?search_keywords&search_keywords_operator=and&search_cat1={perfecturevalue}&search_cat2=0”)
#计算运行页面循环的次数
totalistnum=driver.find\u元素\u by\u css\u选择器(
'div.page_navi2.clearfix>p')。获取属性('text')
totalistnum.text.split(“件中")
如果TotalIstNum[0]%10!=0:
pageLoopCount=math.ceil(TotalIstNum[0])
其他:
持续
currentpage=0
当currentpage
我认为您不应该使用get\u属性。请尝试使用此属性

totalListNum = driver.find_element_by_css_selector('div.page_navi2.clearfix>p').text

首先,您的定位器不是唯一的 使用以下命令:

div.page_navi2.clearfix:nth-of-type(1)>p
或者对于第二个元素:

div.page_navi2.clearfix:nth-of-type(2)>p

第二,如前所述,使用
.text
获取文本。

如果.text不起作用,可以使用.get\u属性('innerHTML')