0

I've imported a list of websites from csv file. I then checked every website to see if this is developed in wordpress or not. Now, I wanted to export wordpress status of every websited as 'Yes' or 'No' into a csv. From this code I could get status as either all 'Yes' or all 'No'. It returns the wordpress status of last runned website as the wordpress status of all websites. E.g: If wordpress status of last runned website is 'Yes' then status of all websites in csv is 'Yes'.

`wpLoginCheck = requests.get(websiteToScan + '/wp-login.php', headers=user_agent)
        print(f"wpLoginCheck: {wpLoginCheck}")
        if wpLoginCheck.status_code == 200:
            df['Status'] = 'Yes'
            df.to_csv('updated.csv', index=False)
        else:
            print ("Not detected")
            df['Status'] = 'No'
            df.to_csv('updated.csv', index=False)`
snakecharmerb
  • 47,570
  • 11
  • 100
  • 153

2 Answers2

0
df['Status'] = 'Yes'

sets the variable 'Status' equal to Yes for all rows. If you want to change the value of a specific cell you need to use

df.at[i, 'Status'] = 'Yes'

Where i is the row index. If you want to add rows as the loop goes on, you can save the results in dictionaries and convert it to a dataframe in the end. See for example How to append rows in a pandas dataframe in a for loop?

jon
  • 35
  • 9
0

One approach would be using apply function of a pandas Dataframe. Given that the website to scan is one of the columns, you could do:

def wpLoginCheck(row):
    requests.get(row['websiteToScan'] + '/wp-login.php', headers=user_agent)
    if wpLoginCheck.status_code == 200:
        return 'Yes'
    else:
        return'No'

df['Status'] = df.apply(wpLoginCheck, axis=1)
df.to_csv('updated.csv', index=False)