用Python删除Instagram的用户名

2024-09-28 05:25:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从一个insta用户那里获取用户名,这似乎很容易做到,但我对Python的了解还不够。有人能帮我吗?我看过这段代码,我认为它很有用,但我不知道如何使用它。在

谢谢。在

from selenium import webdriver
from bs4 import BeautifulSoup

driver= webdriver.Chrome()

driver.get('https://www.instagram.com/michaeljackson/')
soup = BeautifulSoup(driver.page_source,"lxml")
driver.quit()

for item in soup.select('._o6mpc'):
    name = item.select('._kc4z2')[0].text
    followers= item.select('._fd86t')[1].text
following = item.select('._fd86t')[2].text
    print('Name :{}\nFollowers :{}\nFollowing :
{}'.format(name,followers,following))

Tags: text用户namefromimportdriveritemselect
1条回答
网友
1楼 · 发布于 2024-09-28 05:25:26

我建议你在发帖前先检查一下语法。很酷。 所以,正如我们看到的代码,这是一个非常小的抓取代码。在运行代码之前,您需要遵循以下步骤。在

运行代码需要三个库。在

  1. pip install -U selenium。在
  2. 美丽组pip install -U bs4
  3. Lxmlpip install -U lxml

然后从https://sites.google.com/a/chromium.org/chromedriver/下载chrome驱动程序

然后按python code.py运行代码

在你的Python系统中有希望。在

相关问题 更多 >

    热门问题