0

Basically, I am new to python. I have a set of URLs in an excel file and I want to check whether the links are active or inactive and save the active or inactive status column along with the URL column in a new excel file. I found this code working fine but I am unsure of implementing this with excel. can anyone pls help to solve this?

EXCEL before it goes through python

I want something like this from the above

Excel after it went through python code

1 Answers1

0

You can use this code.

import httplib2
import pandas as pd

df = pd.read_excel("test.xlsx")

h = httplib2.Http()

for index, row in df.iterrows():
    if("http" in str(row["urls"])):
        try:
            response, content = h.request(row["urls"])
            if response.status == 200:
                row["status"] = "active"
        except httplib2.ServerNotFoundError:
            row["status"] = "inactive"
    else:
        row["status"] = "No link"

print(df)

Hope to be helpful for you. Thanks.

lionking-123
  • 301
  • 3
  • 12