我使用哪个模块来获取 HTML 元素的内容? [英] Which module do I use to get the content of a HTML element?

查看:35
本文介绍了我使用哪个模块来获取 HTML 元素的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Internet Explorer 导航到一个页面,我能够在一个数组中获取该页面.我想要做的是获取一个 div 文件的内容,例如页面返回

div中的文字

我想得到那个文本,我该怎么做?我正在考虑尝试

->content("someClass");

但它不起作用.

解决方案

With Web::Query:

使用 Web::Query qw();使用 WWW::Mechanize qw();我的 $mech = WWW::Mechanize->new;$mech->get('file:///tmp/so11056483.html');网页::查询->new_from_html($mech->content)->find('div.someClass')-> 文字

表达式返回字符串Text in div

I have a Internet explorer navigate to a page and I am able to get the page in an array. What I want to do is get content of a div file, for example the page returns

<div class="someClass">Text in div</div> 

and I want to get that text, how would I do it? I was thinking of trying

->content("someClass");

but it wouldn't work.

解决方案

With Web::Query:

use Web::Query qw();
use WWW::Mechanize qw();
my $mech = WWW::Mechanize->new;
$mech->get('file:///tmp/so11056483.html');
Web::Query
    ->new_from_html($mech->content)
    ->find('div.someClass')
    ->text

expression returns the string Text in div

这篇关于我使用哪个模块来获取 HTML 元素的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆