2017-04-12 60 views
0

我有一個包含adsense代碼的千頁html頁面(沒有管理面板)。 我想從html中刪除它們。 一個代碼如下所示:如何從整個網站中刪除AdSense代碼

<ins class="adsbygoogle" 
style="display:inline-block;width:160px;height:600px" 
data-ad-client="ca-pub-7165746718333100" 
data-ad-slot="9087512399"></ins> 

另:

<ins class="adsbygoogle" 
style="display:inline-block;width:160px;height:600px" 
data-ad-client="ca-pub-7163746711373100" 
data-ad-slot="7467236139"></ins> 

所有這些相似但不相同。試圖編寫正則表達式來查找並替換爲空字符串,但不成功。

任何suggetion如何自動執行它?

+0

您正在使用哪種語言?最有可能的是,一個解析器(即'BeautifulSoup'或'DOMDocument')就是你正在尋找的東西。 – Jan

+0

一月,我沒有編程語言。我使用這個小程序:http://download-codeplex.sec.s-msft.com/Download/Release?ProjectName=findandreplace&DownloadId=851369&FileTime=130458305187130000&Build=21050。它可以找到並替換文件夾中的所有重複文件。我也知道java和php語言。 – Balconsky

回答

2

可以(注意我的意見,你不應該)使用方法:

(?s:     # parenthesis, turning on dotall mode 
    <ins    # <ins literally 
    (?:(?!</ins>).)*? # anything else lazily afterwards 
         # making sure not to overrun </ins> 
    "adsbygoogle"  # adsbygoogle 
    .*?    # rest 
    </ins>    # closing tag 
) 

完全刪除這些比賽,看到a demo on regex101.com

+0

我試過你的正則表達式,它適用於你的演示,但不能在Notepadd ++或「FindAndReplaceTool」中工作。 – Balconsky

+0

我再試一次。有用。非常感謝你。你節省了我的時間。 – Balconsky