我试图从网页中提取姓名和大学座位号码,但我得到以下结果 - [Agnello Fernandes A(1sp15me001)
]
这是我的代码
import requests
from bs4 import BeautifulSoup
r=requests.get("http://cbcs.fastvturesults.com/student/1sp15me001")
c=r.content
soup=BeautifulSoup(c,"html.parser")
all[0].find_all("p",{"class":"card-title page-title mb-0 mt-0"})
如何将其转换为str元素并提取名称?
答案 0 :(得分:1)
试试这个:
import requests
from bs4 import BeautifulSoup
r = requests.get("http://cbcs.fastvturesults.com/student/1sp15me001")
soup=BeautifulSoup(r.text,"html.parser")
items = soup.find(class_="text-muted")
print("{}\n{}".format(items.previous_sibling,items.text))
输出:
Agnello Fernandes A
(1sp15me001)