我可以使用正则表达式与页面包含从阿贾克斯()函数得到什么?可以使用、函数、页面、正则表达式

2023-09-10 18:21:22 作者:拿着试卷唱忐忑i

我想获得包含在某些网页滚动字幕标记。 这是我的code

I want to get contain from marquee tag in some page. This is my code

var myurl = "http://www.somewhere.com/somepage.html";
var patt = /.+<marquee.+>(.+)<\/marquee>.+/;

$.ajax({
    url: myurl,
    success: function(data){
        var r = patt.exec(data);
        console.debug(r[1]);
    },
});

我发现,变量R为空。 什么是我的错?

I found that, variable r is null. What is my mistake ?

PS。我做一个Chrome扩展,因此它可以让我打电话给阿贾克斯()在其他领域。

PS. I do a chrome extension, so it allows me to call ajax() in other domain.

推荐答案

有很多原因不能与常规的前pressions说我不打算在这里赘述了解析HTML。

There are many reasons for not parsing HTML with regular expressions that I'm not going to go into here.

在你的情况,我怀疑有可能是内换行的&LT;字幕&GT; 标签,你的正则表达式所无法比拟的。

In your case, I suspect that there may be newlines within the <marquee> tag which your regex can't match.

尝试

/<marquee[^>]*>([\s\S]*?)<\/marquee>/

和看看会发生什么。

[\ S \ S] 匹配任何字符(空格或无空格,一个杂牌组装电脑,以弥补JavaScript的缺乏点匹配所有模式),< ?code> * 使比赛出现任意次,但尽可能少,这样我们就不会在多个匹配&LT;字幕&GT; 标签。

[\s\S] matches any character (whitespace or non-whitespace, a kludge to compensate for JavaScripts lack of a "dot matches all" mode), *? allows the match to occur any number of times, but as few as possible so we don't match across multiple <marquee> tags.

 
精彩推荐
图片推荐