文件输出与终端输出不同

时间:2019-07-17 03:49:11

标签: python python-3.x

我正在尝试编写一个程序(用于读取Coles员工的在线日历)并将输出写入ICS文件以用于日历应用程序。

我已经到了要阅读页面源代码并进行筛选以查找排班名册的阶段。

我唯一的问题是,尝试将它们输出到文件时,打印时在终端上显示的输出(正确)与写入我的输出文件的输出不同。

# this is how i collect the page source #
from webbot import Browser

web =  Browser()
web.go_to('https://login.colesgroup.com.au/nidp/saml2/sso?sid=0&option=credential')
web.type('********') #username
web.press(web.Key.TAB)
web.type('********')#password
web.click(id = 'button')
web.click(id = 'a.actionn-item')
web.go_to("https://colesgroup.sharepoint.com/sites/mycoles/Pages/redirect.aspx?feature=myhours")
web.click('Shift Details View')

data = web.get_page_source()



with open('pagesource.txt', 'w') as file:

    file.write(data)

#in another file #
with open("pagesource.txt", 'r') as file:
    for line in file:
        if 'roster-timeblock-home' in line:
            print(line)
            output = line

with open("shifts.txt", 'w') as file:
                file.write(output) # The output that gets written in shifts.txt is different to the terminal output#

shifts.txt中的输出应与终端输出相同,此处

<div class="roster-timeblock roster-timeblock-home" data-date="2019-16-07" style="top: 66.6667%; height: 12.5%; opacity: 1;"><div class="roster-timeblock-time-wrapper"><span class="roster-timeblock-time">16:00<br />19:00</span></div></div></div>

<div class="roster-timeblock roster-timeblock-home" data-date="2019-21-07" style="top: 50%; height: 33.3333%; opacity: 1;"><div class="roster-timeblock-time-wrapper"><span class="roster-timeblock-time">12:00<br />20:00</span></div></div></div>

但是,这就是我得到的

<div class="roster-timeblock roster-timeblock-home" data-date="2019-21-07" style="top: 50%; height: 33.3333%; opacity: 1;"><div class="roster-timeblock-time-wrapper"><span class="roster-timeblock-time">12:00<br />20:00</span></div></div></div>

仅第二个输出... 我可以帮忙吗?我要去哪里错了?

1 个答案:

答案 0 :(得分:0)

您可以在下面看到一个可能的解决方案:

1. $ cd /home/don1k/courses_api/Courses/

2. $ gunicorn --pythonpath/home/don1k/courses_api/Courses --bind 0.0.0.0:8000 Courses.wsgi