URL 목록을 가진 파일에서 중복 된 URL을 제거하고 싶습니다. 내 bugun_url_given.txt는 "http://www.bugun.com.tr/ara/Ak%20Parti/1"을 가지고 있으며 모든 URL을 가져 와서 그들은 모두 고유 한 URL의에 저장 "bugun_url_collection.tx" 여기 내 코드입니다 .. 을 반복됩니다중복 된 URL의 파이썬을 제거하십시오
from cookielib import CookieJar
import urllib2
import json
from bs4 import BeautifulSoup
cj = CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
try:
text_file = open('bugun_url_given.txt', 'r')
for line in text_file:
print line
soup = BeautifulSoup(opener.open(line))
links = soup.select('div.nwslist a')
for link in links:
print link
#unique_url = set(map(lambda url : url.strip("/ "), links))
with open('bugun_url_collection.txt', 'a') as f:
for link in links:
f.write(link.get('href') + '\n')
except ValueError:
pass
은 당신이 지금까지 시도 했습니까? 질문에 코드가 주어진 –