Search code examples
pythonstringpython-requests-html

Compare requests with python


I want to compare two requests (requests to website) with python. In the first step I'll get the response and save that in a variable (f1 and f2). After, I'll want to compare them and if there are difference, I want to know what's the difference. For example, difference can be a new button on the website or text changes of blog article.

import requests

f1 = requests.get(link1)
f2 = requests.get(link2)

if f1.text == f2.text:
   #some code to analyse, what's the difference
   print('f1 and f2 is different')

How can get the difference between f1 and f2 in the best way?


Solution

  • You can split the f1 and f2 by using .split(" ") and then use a for loop to get word for word differences in the two like so:

    differentWords = {}
    f1Split = f1.split(" ")
    f2Split = f2.split(" ")
    for i,b in f1Split,f2Split:
       if(f1Split[i] == f2Split[b]):
          #The words are the same
       else:
          differentWords.append(f"{f1Split}:{f2Split}")
    

    The ideas are there but I think that this should hypothetically be a start to your solution.