小编use*_*763的帖子

美汤条刮

我正在尝试获取文章正文中的所有 p 标签。我想知道是否有人可以解释为什么我的代码是错误的以及我如何改进它。下面是文章的网址和相关代码。感谢您提供的任何见解。

网址:http ://www.france24.com/en/20140310-libya-seize-north-korea-crude-oil-tanker-rebels-port-rebels/

import urllib2
from bs4 import BeautifulSoup

# Ask user to enter URL
url = raw_input("Please enter a valid URL: ")

soup = BeautifulSoup(urllib2.urlopen(url).read())

# retrieve all of the paragraph tags
body = soup.find("div", {'class':'bd'}).get_text()
for tag in body:
    p = soup.find_all('p')
    print str(p) + '\n' + '\n'
Run Code Online (Sandbox Code Playgroud)

beautifulsoup python-2.7

3
推荐指数
1
解决办法
8453
查看次数

标签 统计

beautifulsoup ×1

python-2.7 ×1