Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我怎样才能找到一个特定帖子的链接并从文章中获取数据_Python_Django_Web Scraping_Beautifulsoup - Fatal编程技术网

Python 我怎样才能找到一个特定帖子的链接并从文章中获取数据

Python 我怎样才能找到一个特定帖子的链接并从文章中获取数据,python,django,web-scraping,beautifulsoup,Python,Django,Web Scraping,Beautifulsoup,我正试图从我刮下来的帖子链接,这样我可以保存文本。我有一部分在那里。我只是需要调整一些事情,这就是我来这里的原因。我得到的不是不同的帖子,而是重复的。不仅如此,它们还被这样的括号包围着 [[<div class="article-body" id="image-description"><p>Kanye West premiered the music video for "Famous" off his "The Life of Pablo" albu

我正试图从我刮下来的帖子链接,这样我可以保存文本。我有一部分在那里。我只是需要调整一些事情,这就是我来这里的原因。我得到的不是不同的帖子,而是重复的。不仅如此,它们还被这样的括号包围着

[[<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>], 
我觉得我很接近。这对我来说是全新的。任何帮助都会很好。

我想出来了

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

我试图从结果中删除括号,尽管它们被称为列表。如果你想要里面的东西,你需要迭代它们并提取你想要的东西,那么你的代码是如何与这个用户如此相似的呢?
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