开发者

bookmarklet : how to get the html of the page you want to run the bookmarklet on?

javascript bookmarklets can use document object to get selected text or links. But how do I get the whole html?

I want to get the whole html so that I could retrieve specific data between html tags.

for e.g. I want to get the following text from this page http://www.linguee.de/englisch-deutsch/uebersetzung/futile.html

futile;

zwecklos;

There is no manual removal or exception for end customers at LEVEL 3 - Requests are futile;

Es gibt weder manuelle Entfernungen noch Ausnahmen für Endkunden aus LEVEL 3. Anfragen sind absolut zwecklos;

after getting the html by document.documentElement.innerHTML how do I 开发者_Python百科get the above specific text from the innerhtml?


document.documentElement.innerHTML


You can check my bookmarklets as example. There are some features: 1. It is use post request, so any size of data can be send to server 2. It is use user selection from page 3. It is extract page text content using boilerpipe library.

<a class="button" href="javascript:function post_to_url(path,params,method){method=method||'post';var form=document.createElement('form');form.setAttribute('method', method);form.setAttribute('action',path);form.setAttribute('accept-charset','UTF-8');for(var key in params){var hiddenField=document.createElement('input');hiddenField.setAttribute('type','hidden');hiddenField.setAttribute('name',key);hiddenField.setAttribute('value',params[key]);form.appendChild(hiddenField);}document.body.appendChild(form); form.submit();};var t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.getSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange().text)||location.href);if(t=='')t=location.href;post_to_url('http://g-calendar.appspot.com/analyze/analyze', {withKeywords:'true', message:t, sumSize:5, return_type:'list', title:document.title, url:location.href}, 'post')">
    Summarise
</a>


You can get the tagname with element.tagName, and any attribute of that tag with element.getAttribute('attributename'). Would that get you the data you are trying to get?

If not, can you give us an example of the data you are trying to get?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜