Python 3.x 使用CSS选择器在BeautifulSoup find_all方法中返回空对象

Python 3.x 使用CSS选择器在BeautifulSoup find_all方法中返回空对象,python-3.x,beautifulsoup,css-selectors,python-requests,Python 3.x,Beautifulsoup,Css Selectors,Python Requests,我使用python中的请求模块登录到结果页面。从那里我希望程序打印我的名字,标记等终端使用bs4。使用时 name=soupe.find_all(“td”,“class”:“celldata”})或 names=soupe.find\u all(class=“celldata”)代码运行得非常完美。但是当我为我的名字复制CSS选择器时 namess = soupe.find_all(r'body > table > tbody > tr:nth-of-type(4) >

我使用python中的请求模块登录到结果页面。从那里我希望程序打印我的名字,标记等终端使用bs4。使用时
name=soupe.find_all(“td”,“class”:“celldata”})

names=soupe.find\u all(class=“celldata”)
代码运行得非常完美。但是当我为我的名字复制CSS选择器时

namess = soupe.find_all(r'body > table > tbody > tr:nth-of-type(4) > td > div:nth-of-type(1) > table > tbody > tr:nth-of-type(2) > td:nth-of-type(3)')
这返回了一个空对象。我想它应该还我的名字。这样有什么问题? 还有,有人能告诉我什么时候使用CSS选择器,什么时候手动使用吗

我面临的另一个问题是,在post方法中,当我给出我必须填写表单的网站URL时,即

http://kvpy.iisc.ernet.in/kvpy-1415/checkMarks.php
然后这个程序就不起作用了。我不得不将其更改为包含学生姓名和排名等的页面URL

http://kvpy.iisc.ernet.in/kvpy-1415/checkMarksSuccess.php
填好表格后就可以了。 为什么会这样

以下是完整的代码:

import requests
import bs4

s = requests.Session()

payload = {'id': '15015556', 'dd' : '25', 'mm' : '09', 'yyyy' : '1998'}

r = s.post(r'http://kvpy.iisc.ernet.in/kvpy-1415/checkMarksSuccess.php', payload)

if (r.text.find("Name of the Candidate")) >= 0:
    soupe = bs4.BeautifulSoup(r.content, "lxml")
    name = soupe.findAll("td", {"class": "celldata"})

    names = soupe.find_all(class_="celldata")

    namess = soupe.find_all(r'body > table > tbody > tr:nth-of-type(4) > td > div:nth-of-type(1) > table > tbody > tr:nth-of-type(2) > td:nth-of-type(3)')
    print (namess)

    '''for n in name:
        print(n.get_text())'''
else:
    print("failure")

您是否尝试过选择
而不是
全部查找
?对于那个长选择器应该工作得更好。