2016-11-04 5 views
0

CSV 파일에서 수집 된 여러 URL에서 기사를 추출하려고합니다. I 출력을 인쇄 할 때 그러나 나는이 오류가 발생합니다 : InvalidSchema을 : 없음 연결 어댑터는 나는 내가 그것을 인쇄 할 때 문제가 "행"에 생각 '['http://www.nytimes.com/2016/10/06/world/europe/police-brussels-knife-terrorism.html ']'연결 어댑터가 없습니다. 파이썬 3.5 | 요청

import csv 
import requests 
from bs4 import BeautifulSoup 

with open('Training_news.csv', newline='') as file: 
    reader= csv.reader (file, delimiter=' ') 
    for row in reader: 
     r=requests.get(row) 
     r.encoding = "ISO-8859-1" 
     soup = BeautifulSoup(r.content, 'lxml') 
     text = soup.find_all(("p",{"class": "story-body-text story-content"})) 

을 찾을 수 없습니다 CSV 파일하지만 파일의 단일 값에 대한 목록에있는 모든 URL을 하나의 목록을 얻을하지 않습니다 는 [ 'http://www.nytimes.com/2016/10/06/world/europe/police-brussels-knife-terrorism.html'] [ 'http://www.nytimes.com/2016/06/29/world/europe/turkey-istanbul-airport-explosions.html']

답변

0

row이 목록입니다. requests.get은 문자열을 필요로합니다. 이렇게하면 각 행의 항목을 반복 할 수 있습니다.

with open('Training_news.csv', newline='') as file: 
    reader= csv.reader (file, delimiter=' ') 
    for row in reader: 
     for url in row: 
      r=requests.get(url) 
      r.encoding = "ISO-8859-1" 
      soup = BeautifulSoup(r.content, 'lxml') 
      text = soup.find_all(("p",{"class": "story-body-text story-content"}))