简体   繁体   English

Instagram 抓取:如何使用 selenium Python 获取 Instagram 个人资料名称

[英]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.下午好,我目前正在尝试检索某个 instagram 个人资料的以下字段(个人资料的名称 [不是用户名],如下所示的用户名。

Therefore, I'm looking for the code to get the field: "yereni028k" (the profile's name, that is).因此,我正在寻找获取该字段的代码:“yereni028k”(即配置文件的名称)。 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. Css 选择器是获取元素的更好方法。

"UPDATE" if you wanna use Xpath then use the below code: “更新”如果你想使用 Xpath 然后使用下面的代码:

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

use the code as below使用如下代码

driver.find_element_by_xpath("//a[contains(.,'followers')]/ancestor::ul/following-sibling::div/h1).text

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM