【发布时间】:2017-03-12 22:08:01
【问题描述】:
import numpy as np
import json
import re
from urllib.request import urlopen
from bs4 import BeautifulSoup
url = "http://www.npr.org/sections/thetwo-way/2017/03/06/518805720/turkey-germany-relations-at-new-low-after-erdogan-makes-nazi-comparison"
html = urlopen(url)
bsObj = BeautifulSoup(html, 'lxml')
def keyInfo(div):
print(div.find("h1").get_text())
print(div.find("span", {"class":"date"}).get_text())
print(div.find("a", {"rel":"author"}).get_text().strip())
print(div.findAll("p")) # Problem here
keyInfo(bsObj)
问题是def keyInfo中的最后一行,它打印了很多东西,标签,标题,我只想要文本的主要内容,我怎么能做到这一点?
【问题讨论】:
-
请重新访问如何在 Stack Overflow 上提问 good question,以便您的问题得到社区的好评。此外,请确保您熟悉如何组合minimal reproducible example。请记住,此处提供的帮助是针对您要解决的问题中的编程问题的明确问题。实际上,这太宽泛了,因为您没有提供足够的信息让读者能够有效地帮助您。
-
修改了,够清楚了吗?