2016-12-02 5 views
0
私はPythonが新聞サイトをこすり、さまざまなHTMLタグを削除した後に、テキスト内の実際の物語を収集するために使用しています

など自分好みブロッカー()

import urllib.request 
from bs4 import BeautifulSoup 

#targetURL = 'http://indianexpress.com/article/india/mamata-banerjee-army-deployment-nh-2-in-west-bengal-military-coup-4405871' 
targetURL = "http://timesofindia.indiatimes.com/india/Congress-Twitter-hacking-Police-form-cyber-team-launch-probe/articleshow/55737598.cms" 
#targetURL = 'http://www.telegraphindia.com/1161201/jsp/nation/story_122343.jsp#.WEDzfXV948o' 

with urllib.request.urlopen(targetURL) as url: 
    html = url.read() 
soup = BeautifulSoup(html,'lxml') 

for el in soup.find_all("p"): 
    print (el.text) 
を次のように

私の簡単なコードです

indianexpress.comのURLまたはtelegraphindia.comのURLにアクセスしているとき、コードはうまくいきます。私は、純粋なテキスト形式で、迷惑なことなく、物語を広げています。

私はこの自分好みブロッカーをバイパスし、ページを取得取得する方法
We have noticed that you have an ad blocker enabled which restricts ads served on the site. 
Please disable to continue reading. 

:?timesofindia.comサイトは、adblockのダウンロードブロッカーを持っており、次のようにこの場合には、出力されているが

提案に感謝します

答えて

0

実際に抽出しようとしているコンテンツが<p>タグの内部にないようです。しかし、広告ブロッカーの警告はそのようなタグの内側にあります。このテキストは常にHTMLドキュメントの一部ですが、広告が読み込まれない場合にのみユーザーに表示されます。

代わりに<arttextxml>タグの内容を抽出してみてください。

関連する問題