이 코드는 bbc의 뉴스 콘텐츠를 긁어 모으기 위해 작성되었습니다. 지금까지는 작동하지만 단락 태그를 표시합니다. 정규식을 사용하여 html 태그를 제거하려고했지만 여전히 작동하지 않습니다. 제발 이걸로 도움이 필요해.단락 태그를 벗을 수 없습니다.
감사
import feedparser
from bs4 import BeautifulSoup
import urllib2
from urllib2 import urlopen
import re
import cookielib
from cookielib import CookieJar
import time
import os
cj = CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders= [('User-agent','Mozilla')]
bbcRSSFeed = feedparser.parse('http://feeds.bbci.co.uk/news/rss.xml')
numberstories=[len(bbcRSSFeed)]
FeedLinks=[]
FeedTitles=[]
for post in bbcRSSFeed.entries:
FeedLinks.append(post.link)
FeedTitles.append(post.title)
limit=2
counter=0
paraStringList = []
for i in FeedLinks:
#if counter<FeedLinks: #displays the content of every link
if counter<limit:
print "["+i +"]"
newpage = urlopen(i)
soup = BeautifulSoup(newpage)
text = soup.select('.story-body p') #content of the news story
print (text)
counter+=1
3.2.1 ... 감사 – hepzibah
피드, 나는 각 피드에서 콘텐츠를 긁어 할 수 그러나 지금 파일로 자신의 타이틀 개별 TXT 파일에 각 출력을 저장하려고했다 이름 타일 예 : newstitle1.txt, newstitle2.txt ...하지만 지금까지, 아래 코드를 사용하여, 나에게 index.txt 예를 들어 0.txt, 1.txt ....이 문제를 해결하는 방법에 대한 아이디어? handle ('textfile.txt', 'w')을 핸들로 사용 : handle.write ('text') – hepzibah
후속 질문은 의견에 맞지 않습니다. 그것들에 대해 더 나은 새로운 질문을하십시오. –