Instagram scraping: How to get the Instagram Profile Name using selenium Python

Good afternoon, I’m currently attempting to retrieve the following field of a certain instagram profile (the profile’s name [not the username] as shown below the username.

Therefore, I’m looking for the code to get the field: “yereni028k” (the profile’s name, that is). I do have the following code to retrieve the other data in the profile:

   posts = wait.until(EC.presence_of_element_located((By.XPATH, '//li/span[text()=" posts"]/span'))).text
    followers = wait.until(EC.presence_of_element_located((By.XPATH, '//li/a[text()=" followers"]/span'))).text
    following = wait.until(EC.presence_of_element_located((By.XPATH, '//li/a[text()=" following"]/span'))).text
name = ( ..... )  #profile's name

Thanks for all your help.


If you can have a try with below code:

name = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".-vDIg h1"))).text

user_name = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "_7UhW9.fKFbl.yUEEX.KV-D4.fDxYl"))).text

Css selectors are a better way to get element.

“UPDATE” if you wanna use Xpath then use the below code:

name = wait.until(EC.presence_of_element_located((By.XPATH, "/html/body/div[1]/section/main/div/header/section/div[2]/h1"))).text

user_name = wait.until(EC.presence_of_element_located((By.XPATH, "/html/body/div[1]/section/main/div/header/section/div[1]/h2"))).text