请各位老师指点一下,请问用BeautifulSoup如何获取p标签内的值

请各位老师指点一下,请问用BeautifulSoup如何获取p标签内的值,第1张

推荐使用的是 PyCharm,大部分用的都是这个,还有一部分坚守再sublime text上:

mport urllib

from BeautifulSoup import BeautifulSoup

url = 连接;

allData=

content = urlliburlopen(url)read()

soup = BeautifulSoup(content)

tags1 = soupfindAll('tr', {class: even right})

tags2 = soupfindAll('tr', {class: odd right})

上面的就是利用写的一些代码,是要取出网页中class 为even right 的所有tr和所有class为odd right的所有tr取出之后就可以打印出他的内容。

使用jquery 获取相应的元素非常简便。

// 获取第一个p标签

const firstP = $('p:first');

// 获取最后一个p标签

const lastP = $('p:last');

consolelog(firstP, lastP);

我能哈哈你这段html里面正好有个onclick事件如果连这个都没有那就不好了既然有我们直接调用js代码即可WebBrowser1OleObjectdocumentparentWindowsaveForm1();试一下,goodluck路就在脚下,兄弟

界面中需要一个按钮command1,一个MS internet controls 名为webbrowser1,代码如下:

Private Sub Command1_Click()

WebBrowser1Navigate ">

IE下用 eventsrcElementinnerHTML

firefox下通过函数参数传递event对象,然后用targetinnerHTML

实现细节,自己百度

$text = '

<p>111</p>

<p>222</p>

<p>333</p>

<p>444</p>

<p>555</p>

<p>666</p>

';

$pattern = '/(<p>[A-z0-9]<\/p>)/i';

var_dump(array_slice(preg_get($pattern , $text),0,3));

function preg_get($pattern , $text)

{

$out = array();

preg_match_all( $pattern , $text, $out );

return $out[1];

}

xpath 如果返回的是多个元素的话,比如你这里就是多个<p> 那就要用到循环

content=""

for selector  in selxpath('//div[@class="document"]//p'):

    content=content+ selectorxpath("/text()")extract()

以上就是关于请各位老师指点一下,请问用BeautifulSoup如何获取p标签内的值全部的内容,包括:请各位老师指点一下,请问用BeautifulSoup如何获取p标签内的值、js怎么获取网页中第n个p元素、winfrom WebBrowser取网页p标签的值,没有id和name,只有class,怎么获取里面的内容等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/10140826.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-05
下一篇2023-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存