Remove unwanted content on client side browser

时间:2016-05-11 11:29:30

标签: javascript python selenium

This will be used for removing unwanted content within my automated selenium scripts!

My question: Is it possible on the client side to remove unwanted HTML code using JavaScript or some other technology?

Example scenario:

  • Facebook timeline defaults to 10 posts at max on screen at any time
  • I load facebook and 10 posts are generated [ 2 of these posts are by user 'John' ]
  • I run a [JavaScript?] script that will grab all divs where the content is posted by user 'John' and remove them from my browser
  • ** 2 new posts are generated automatically -- or not ! (The requirement is to remove unwanted content (similar to AdBlocker?).. if the site generates 2 new posts, that's a plus!)

I'm not looking for someone to code me a solution to this problem, but instead push me in the right direction (a solution is a bonus!)

I will then update this question (if it lives) with the solution I have come up with and clean up the post !

NOTE: I understand Facebook already has a built in 'stop following' button to cover this. The scenario could be that if the content includes 'someone you might know!' then I want to remove this section of HTML from my browser !

Update: Since there's no code, I've added another example scenario!

  • I load this SO question in selenium
  • I'm so confident that this post will get voted up rather than down!

HTML currently contains:

 <div id="content">
     <p>
         <em>prepares for -10 within seconds<em>
     </p>
 </div>
  • I run a [JavaScript?] script in the current browser which searches the HTML for 'prepares for -10 within seconds'
  • If found, I want to remove the parent section and all of its content

HTML then contains:

 <div id="content">
 </div>

1 个答案:

答案 0 :(得分:1)

BrowserMob Proxy之类的代理怎么样...他们的着陆页读取,

  

它可以捕获Web应用程序的性能数据(通过HAR格式),如   以及操纵浏览器行为和流量,例如白名单   并将内容列入黑名单,模拟网络流量和延迟,以及   重写HTTP请求和响应。

您可以使用代理过滤掉您想要删除的元素。