2016-06-25 1 views
1

私は撤去した投稿からのリンクをたどろうとしているので、テキストを保存できます。私は部分的にそこにいる。私はちょうど私がここにいる理由でいくつかのものを調整する必要があります。別の投稿の代わりに私は重複を取得しています。そしてそれだけでなく、彼らは私が近いんだように私は感じるこのどのように特定の投稿へのリンクをたどり、そのデータを削り取ることができますか?

[[<div class="article-body" id="image-description"><p>Kanye West premiered 
     the music video for "Famous" off his "The Life of Pablo" album to a 
     sold out audience in Los Angeles. The video features nude versions of George W. Bush. 
     Donald Trump. Anna Wintour. Rihanna. Chris Brown. Taylor Swift. 
     Kanye West. Kim Kardashian. Ray J. Amber Rose. Caitlyn Jenner. 
    Bill Cosby (in that order).</p></div>], 

とHERESに私のコード

def sprinkle(): 
     url_two = 'http://www.example.com' 
     html = requests.get(url_two, headers=headers) 
     soup = BeautifulSoup(html.text, 'html5lib') 
     titles = soup.find_all('div', {'class': 'entry-pos-1'}) 

     def make_soup(url): 
      the_comments_page = requests.get(url, headers=headers) 
      soupdata = BeautifulSoup(the_comments_page.text, 'html5lib') 
      comment = soupdata.find_all('div', {'class': 'article-body'}) 
      return comment 

     comment_links = [url_two + link.a.get('href') for link in titles] 

     soup = [make_soup(comments) for comments in comment_links] 
      # soup = make_soup(comments) 
      # print(soup) 

     entries = [{'href': url_two + div.a.get('href'), 
        'src': url_two + div.a.img.get('data-original'), 
        'text': div.find('p', 'entry-title').text, 
        'comments': soup 
        } for div in titles][:6] 

     return entries 

のような括弧で囲まれています。これは私にとって初めてのことです。どんな助けも素晴らしいだろう。

+1

ものの結果からのにカッコを削除しようとしている

def sprinkle(): url_two = 'http://www.vladtv.com' html = requests.get(url_two, headers=headers) soup = BeautifulSoup(html.text, 'html5lib') titles = soup.find_all('div', {'class': 'entry-pos-1'}) def make_soup(url): the_comments_page = requests.get(url, headers=headers) soupdata = BeautifulSoup(the_comments_page.text, 'html5lib') comment = soupdata.find('div', {'class': 'article-body'}) para = comment.find_all('p') return para entries = [{'href': url_two + div.a.get('href'), 'src': url_two + div.a.img.get('data-original'), 'text': div.find('p', 'entry-title').text, 'comments': make_soup(url_two + div.a.get('href')) } for div in titles][:6] return entries 

それを考え出しました。あなたが内部にあるものを必要とする場合は、それらを反復処理し、あなたが望むものを抽出する必要があります。また、あなたのコードはこのユーザと似ていますか?http://stackoverflow.com/questions/38022573/whats-the-proper-syntax-to- Djを使用してリンクを使用してfollow-a-link-yous-request? –

答えて

2

私は、私は彼らがリストと呼ばれている

関連する問題