首页 \ 问答 \ Python Web Scraping:无法从bs4元素中提取文本(Python Web Scraping: Unable to extract text from bs4 element)

Python Web Scraping:无法从bs4元素中提取文本(Python Web Scraping: Unable to extract text from bs4 element)

我试图从网页中提取姓名和大学座席号,但我得到以下结果 - [Agnello Fernandes A(1sp15me001)

]
这是一个bs4元素。 我需要提取'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元素并提取名称?


I was trying to extract Name and University Seat number from a webpage but I'm getting the following result- [Agnello Fernandes A (1sp15me001)

]
which is a bs4 element. I need to extract 'Agnello Fernandes A' and 1sp15me001.

Here is my code

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"})

How can I convert this to an str element and extract the name?


原文:https://stackoverflow.com/questions/50613364
更新时间:2023-12-28 07:12

最满意答案

据我所知,你希望将子菜单悬停在上面一级的列表项上

<ul class="submenu">
    <li><a href="#">Working With Us</a></li>
    <li><a href="#">Work Culture</a>
        <ul class="submenu">
            <li><a href="#">Benefits</a></li>
        </ul>
    </li>
</ul>

我将子菜单类添加到我希望它们最初隐藏的所有元素中。 然后我对jquery代码进行了一些修改,以便与所有子菜单一起使用

$('ul.submenu').hide();
$('ul.nav > li, ul.submenu > li').hover(function () {
if ($('> ul.submenu',this).length > 0) {
    $('> ul.submenu',this).stop().slideDown('slow');
}
},function () {
    if ($('> ul.submenu',this).length > 0) {
        $('> ul.submenu',this).stop().slideUp('slow');
    }
});

希望这对你有用http://tsfiddle.net/U7mqM/


as far as i understood you want to slidedown the submenu on hovering the list item one level above

<ul class="submenu">
    <li><a href="#">Working With Us</a></li>
    <li><a href="#">Work Culture</a>
        <ul class="submenu">
            <li><a href="#">Benefits</a></li>
        </ul>
    </li>
</ul>

i added the submenu class to all elements i want them to be initially hidden. then i made some modifications on the jquery code to work with all submenus

$('ul.submenu').hide();
$('ul.nav > li, ul.submenu > li').hover(function () {
if ($('> ul.submenu',this).length > 0) {
    $('> ul.submenu',this).stop().slideDown('slow');
}
},function () {
    if ($('> ul.submenu',this).length > 0) {
        $('> ul.submenu',this).stop().slideUp('slow');
    }
});

hope this will work for you see http://jsfiddle.net/U7mqM/

相关问答

更多
  • 在css 更改 #Menu ul ul { display: none; position: absolute; top: 40px; } 至 #Menu ul ul { display: none; position: absolute; padding-top: 40px; } In css change #Menu ul ul { display: none; position: absolute; ...
  • 请在下面找到更新后的代码 ,希望它能解决您的问题。 让我知道你面对的任何进一步的问题。 #nav{ margin: 0 ; padding: 0; position:fixed; width:100%; background:#e7e7e7} #nav li { list-style: none; display: inline-block; float:left} #nav li a{ padding:10px 20px; display: inline-block; text ...
  • 我对你的html代码进行了简单的更改,并使用css实现了hove效果: 请参阅此codepen.io/anon/pen/PNmyKR I made simple change on your html code and made hove effect with css: See this codepen.io/anon/pen/PNmyKR
  • 我没有测试以下代码,但它应该工作... $('.nav-main .container li').hover(function() { if ($(this).find('.submenu').length > 0) { $(this).addClass("hover"); $(this).find('.submenu').show(); } }, function() { var submenu = $(this).find('.submenu'); ...
  • 将您的JQuery更改为: $('.menu li').hover( function () { $(this).find('.submenu').show(); }, function () { $(this).find('.submenu').hide(); } ); 添加$(this).find()意味着它只会显示相关的子菜单,这意味着您的导航中可以有多个子菜单 Change your JQuery to : $('.menu li').hover( functi ...
  • 这是来自Apple的示例代码,看看并创建一个您需要的 This is a sample code from Apple, have a look and create one which you need here
  • 从#main_nav ul ul中删除“top”和“left”,如下所示: #main_nav ul ul { position: absolute; visibility: hidden; } 这是因为“位置:绝对”的运作方式。 在您的情况下,父“li”具有“position:static”(默认),在这种情况下,“position:absolute”使子ul在整个文档中绝对放置。 如果您只是删除“visiblity:hidden”,然后将它放在页面底部,您就可以看到这一点。 另一种解决 ...
  • 相关文章

    更多
  • Web scraper open source
  • (转)Python WEB应用框架纵览
  • Python实现用Hadoop的map/reduce对web日志进行统计
  • Unable to load configuration.
  • Python资源索引 【转载】
  • [DAL]Web2py DAL与Postgres
  • 图片篇-高性能WEB开发
  • 了解 Web Part 框架
  • Shiro整合到Web应用
  • 【转帖】Python 资源索引
  • 最新问答

    更多
  • 如何检索Ember.js模型的所有属性(How to retrieve all properties of an Ember.js model)
  • maven中snapshot快照库和release发布库的区别和作用
  • arraylist中的搜索元素(Search element in arraylist)
  • 从mysli_fetch_array中获取选定的值并输出(Get selected value from mysli_fetch_array and output)
  • Windows Phone上的可用共享扩展(Available Share Extensions on Windows Phone)
  • 如何在命令提示符下将日期设置为文件名(How to set file name as date in command prompt)
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • 从iframe访问父页面的id元素(accessing id element of parent page from iframe)
  • linux的常用命令干什么用的
  • Feign Client + Eureka POST请求正文(Feign Client + Eureka POST request body)
  • 怎么删除禁用RHEL/CentOS 7上不需要的服务
  • 为什么Gradle运行测试两次?(Why does Gradle run tests twice?)
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在android中的活动之间切换?(Switching between activities in android?)
  • Perforce:如何从Depot到Workspace丢失文件?(Perforce: how to get missing file from Depot to Workspace?)
  • Webform页面避免运行服务器(Webform page avoiding runat server)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 内存布局破解(memory layout hack)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • 我们可以有一个调度程序,你可以异步添加东西,但会同步按顺序执行吗?(Can we have a dispatcher that you can add things todo asynchronously but will be executed in that order synchronously?)
  • “FROM a,b”和“FROM a FULL OUTER JOIN b”之间有什么区别?(What is the difference between “FROM a, b” and “FROM a FULL OUTER JOIN b”?)
  • Java中的不可变类(Immutable class in Java)
  • bat批处理文件结果导出到txt
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • 德州新起点计算机培训学校主要课程有什么?
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • “latin1_german1_ci”整理来自哪里?(Where is “latin1_german1_ci” collation coming from?)