fork download
  1. from bs4 import BeautifulSoup
  2. import csv
  3. import os
  4. import re
  5. import requests
  6.  
  7. ## delete only if file exists ##
  8.  
  9. if os.path.exists('KOSPI200.csv'):
  10. os.remove('KOSPI200.csv')
  11. else:
  12. print("Sorry , I can not remove {} file.".format('KOPSPI200.csv'))
  13.  
  14. BaseUrl = 'https://f...content-available-to-author-only...r.com/sise/entryJongmok.nhn?&page='
  15.  
  16.  
  17. for i in range(1,22,1):
  18. try:
  19. url = BaseUrl + str(i)
  20. r = reuqests.get(url)
  21. soup = BeautifulSoup(r.text,'lxml')
  22. items = soup.find_all('td',{'class':'ctg'})
  23.  
  24. for item in items:
  25. #print(item)
  26. txt = item.a.get('href')
  27. k = re.search('[\d]+',txt)
  28. if k:
  29. code = k.group()
  30. name = item.text
  31. data = code, name
  32.  
  33. with open ('KOSPI200.csv','a') as f:
  34. writer=csv.writer(f)
  35. writer.writerow(data)
  36. except:
  37. pass
  38. finally:
  39. temp_for_sort = []
  40. with open ('KOSPI200.csv','r') as in_file:
  41. for sort_line in in_file:
  42. temp_for_sort.append(sort_line)
  43.  
  44. with open('KOSPI200.csv','w') as out_file:
  45. seen = set()
  46. for line in temp_for_sort:
  47. if line in seen: continue
  48.  
  49. seen.add(line)
  50. out_file.wrte(line)
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class, interface, or enum expected
from bs4 import BeautifulSoup
^
Main.java:1: error: '.' expected
from bs4 import BeautifulSoup
                             ^
Main.java:2: error: ';' expected
import csv
      ^
Main.java:3: error: '.' expected
import os
         ^
Main.java:4: error: ';' expected
import re
      ^
Main.java:7: error: illegal character: '#'
## delete only if file exists ## 
^
Main.java:7: error: illegal character: '#'
## delete only if file exists ## 
 ^
Main.java:7: error: class, interface, or enum expected
## delete only if file exists ## 
   ^
Main.java:7: error: illegal character: '#'
## delete only if file exists ## 
                              ^
Main.java:7: error: illegal character: '#'
## delete only if file exists ## 
                               ^
Main.java:9: error: unclosed character literal
if os.path.exists('KOSPI200.csv'): 
                  ^
Main.java:9: error: unclosed character literal
if os.path.exists('KOSPI200.csv'): 
                               ^
Main.java:10: error: unclosed character literal
    os.remove('KOSPI200.csv')
              ^
Main.java:10: error: unclosed character literal
    os.remove('KOSPI200.csv')
                           ^
Main.java:12: error: unclosed character literal
    print("Sorry , I can not remove {} file.".format('KOPSPI200.csv'))
                                                     ^
Main.java:12: error: unclosed character literal
    print("Sorry , I can not remove {} file.".format('KOPSPI200.csv'))
                                                                   ^
Main.java:14: error: unclosed character literal
BaseUrl = 'https://finance.naver.com/sise/entryJongmok.nhn?&page='
          ^
Main.java:21: error: unclosed character literal
        soup = BeautifulSoup(r.text,'lxml')
                                    ^
Main.java:21: error: unclosed character literal
        soup = BeautifulSoup(r.text,'lxml')
                                         ^
Main.java:22: error: unclosed character literal
        items = soup.find_all('td',{'class':'ctg'})
                              ^
Main.java:22: error: unclosed character literal
        items = soup.find_all('td',{'class':'ctg'})
                                 ^
Main.java:22: error: unclosed character literal
        items = soup.find_all('td',{'class':'ctg'})
                                    ^
Main.java:22: error: unclosed character literal
        items = soup.find_all('td',{'class':'ctg'})
                                                ^
Main.java:25: error: illegal character: '#'
            #print(item)
            ^
Main.java:26: error: unclosed character literal
            txt = item.a.get('href')
                             ^
Main.java:26: error: unclosed character literal
            txt = item.a.get('href')
                                  ^
Main.java:27: error: unclosed character literal
            k = re.search('[\d]+',txt)
                          ^
Main.java:27: error: illegal character: '\'
            k = re.search('[\d]+',txt)
                            ^
Main.java:27: error: unclosed character literal
            k = re.search('[\d]+',txt)
                                ^
Main.java:33: error: unclosed character literal
                with open ('KOSPI200.csv','a') as f:
                           ^
Main.java:33: error: unclosed character literal
                with open ('KOSPI200.csv','a') as f:
                                            ^
Main.java:40: error: unclosed character literal
        with open ('KOSPI200.csv','r') as in_file:
                   ^
Main.java:40: error: unclosed character literal
        with open ('KOSPI200.csv','r') as in_file:
                                    ^
Main.java:44: error: unclosed character literal
        with open('KOSPI200.csv','w') as out_file:
                  ^
Main.java:44: error: unclosed character literal
        with open('KOSPI200.csv','w') as out_file:
                                   ^
35 errors
stdout
Standard output is empty