2017-11-08 7 views
-1

this websiteからコンテンツを取得するためにPythonを使用したいと思います。 ページは次のようになります。 enter image description hereウェブサイトからコンテンツを取得できません

しかし、私はソースコードを見たかのpythonでページを読んだとき、それはすべてのページが同じである。この enter image description here

のように見えます。以下

私のpythonコード:

req=urllib.request.Request(url,headers=headers) 
response=urllib.request.urlopen(req) 
`content=response.read()` 
`print(content.get_text())` 

が私を助けてください... スープ= BeautifulSoup(コンテンツ、 'lxmlの')

+0

あなたはHTMLレスポンスの部分だけを見ているようです。あなたが期待している部分がに落ちないと確信していますか? – Matt

+0

あなたの答えをありがとう!私は検索しました、検査の要素は、部分を参照してください;ソースコードを表示するcann; tを参照してください;私のpythonコードも部分を見ることができません。 –

答えて

0

はこれを試してみてください。

from bs4 import BeautifulSoup 
import requests, re 

def remove_some_special_tags(raw_html_data): 

    scripts = re.compile(r'<(script).*?</\1>(?s)') 
    css = re.compile(r'<style.*?/style>') 
    comments = re.compile(r"<!--(.|\s|\n)*?-->") 

    text = scripts.sub('', raw_html_data.lstrip("<!doctype html>")) 
    text = css.sub('', text) 
    text = comments.sub('', text) 

    return text 

url = "https://www.itslaw.com/detail?judgementId=29124888-491d-47ce-a88f-af9ccf003f7c&area=1&index=1&sortType=1&count=5369531&conditions=searchWord%2B%E5%80%9F%E8%B4%B7%2B1%2B%E5%80%9F%E8%B4%B7." 
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'} 
response = requests.get(url, headers=headers) 
raw_data = str(response.content, encoding="utf-8") 

html_beauty = remove_some_special_tags(raw_data) 

soup = BeautifulSoup(html_beauty, 'lxml') 
all_text = ''.join(soup.findAll(text=True)).replace("\n\n", "\n") 


print(all_text) 

グッドラック。 ..

+0

ありがとう!しかし、このコードでも私が望むコンテンツを手に入れることはできません。 –

関連する問題