如何将屏幕抓取数据与文件进行比较。

时间:2018-02-07 00:06:53

标签: python selenium comparison screen-scraping

我使用selenium创建了一个屏幕抓取程序,它打印出一些变量。我想把它吐出的数字与文本文档中的数字进行比较。我不确定这个过程。什么是最好的方法来解决这个问题。文本文件将包含3个数字,将与3个已被屏幕抓取的数字进行比较。

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
#The above is downloading the needed files for this code to work
chrome_path = r"C:\Users\ashabandha\Downloads\chromedriver_win32\chromedriver.exe"
driver = webdriver.Chrome(chrome_path)
driver.get("https://signin.acellus.com/SignIn/index.html")
time.sleep(2)
username = driver.find_element_by_id("Name")
password = driver.find_element_by_id("Psswrd")
username.send_keys("my login")
password.send_keys("my password")
time.sleep(2)
driver.find_element_by_xpath("""//*[@id="loginform"]/table[2]/tbody/tr/td[2]/input""").click()
#The program has now signed in and is going to navigate to the progress tab
time.sleep(2)
driver.get("https://admin252.acellus.com/StudentFunctions/progress.html?ClassID=484")
time.sleep(2)
#now we are on the progress tab
posts = driver.find_elements_by_class_name("Object7069")
time.sleep(2)
for post in posts:
    print (post.text)
#this gives me the first class log
time.sleep(2)
driver.get("https://admin252.acellus.com/StudentFunctions/progress.html?ClassID=326")
#This gives me second class log
time.sleep(2)
posts = driver.find_elements_by_class_name("Object7069")
time.sleep(2)
for post in posts:
    print (post.text)
time.sleep(2)
driver.get("https://admin252.acellus.com/StudentFunctions/progress.html?ClassID=292")
posts = driver.find_elements_by_class_name("Object7069")
time.sleep(2)
for post in posts:
    print (post.text)

1 个答案:

答案 0 :(得分:0)

将selenium输出保存在数据结构(如列表或字典)上,然后打开文件,提取要与之比较的信息,并执行您希望的算法或表达式:https://www.python.org/doc/ 检查出使用文件。