Exemplo n.º 1
0
def test_read_style_iter(tmpdir):
    '''
    Test if cell styles are read properly in iter mode.
    '''
    tmpdir.chdir()
    from openpyexcel import Workbook
    from openpyexcel.styles import Font

    FONT_NAME = "Times New Roman"
    FONT_SIZE = 15
    ft = Font(name=FONT_NAME, size=FONT_SIZE)

    wb = Workbook()
    ws = wb.worksheets[0]
    cell = ws['A1']
    cell.font = ft

    xlsx_file = "read_only_styles.xlsx"
    wb.save(xlsx_file)

    wb_iter = load_workbook(xlsx_file, read_only=True)
    ws_iter = wb_iter.worksheets[0]
    cell = ws_iter['A1']

    assert cell.font == ft
Exemplo n.º 2
0
 def __init__(self):
     super().__init__()
     self.filename = "coin.xlsx"
     try:
         self.wb = load_workbook(filename=self.filename)
         self.current_columns = len(self.wb.active[1]) + 1
     except FileNotFoundError:
         wb = Workbook()
         wb.save(self.filename)
         self.wb = load_workbook(filename=self.filename)
         self.current_columns = 1
from selenium import webdriver
from openpyexcel import Workbook

driver = webdriver.Chrome('chromedriver')

url = "https://search.naver.com/search.naver?where=news&sm=tab_jum&query=추석"

driver.get(url)
req = driver.page_source
soup = BeautifulSoup(req, 'html.parser')
articles = soup.select(
    "#main_pack > div.news.mynews.section._prs_nws > ul > li")

wb = Workbook()
ws1 = wb.active
ws1.title = "articles"
ws1.append(["제목", "링크", "신문사"])

for article in articles:
    title = article.select_one('dl > dt > a').text
    url = article.select_one('dl > dt > a')['href']
    comp = article.select_one("span._sp_each_source").text.split(
        ' ')[0].replace('언론사', '')
    ws1.append([title, url, comp])

    #print(title, url, comp)
    #print(comp)

driver.quit()
wb.save(filename='articles.xlsx')