【问题标题】:Extract social links from any website in python BeautifulSoup or selenium [closed]从 python BeautifulSoup 或 selenium 中的任何网站提取社交链接 [关闭]
【发布时间】:2020-12-02 07:10:54
【问题描述】:

我想要一个自动化的 Python 程序来获取该网站中存在的特定网站的社交媒体(LinkedIn 链接)。链接可能会在更改到另一个网站后,但程序必须独立于链接更改,并且应该为每个网站链接获取linkedIn链接(如果可用)。 总之:我想要一个通用的 python 程序来获取给定网站 url 的社交媒体链接。 谢谢

等待您的帮助和善意的回应。 – 我尝试了很多,但找不到方法。 @poojan请帮助...... 谢谢

【问题讨论】:

  • 请向我们展示您的代码。我们将帮助您制作程序,但不会编写它。

标签: python web-scraping beautifulsoup jupyter-notebook


【解决方案1】:

可能对你有帮助

从这里你可以找到所有的链接

from selenium import webdriver
import time

driver = webdriver.Chrome()
driver.maximize_window()

driver.get('https://www.instagram.com/?hl=en')

# here you can find all the links
links = driver.find_elements_by_tag_name("a")
time.sleep(3)

# printing how many links are there
print(len(links))

# printing the link text using for loop
for link in links:
        print(link.text)

# if you want you can use if statements to check whether they are social media links or not

希望你明白了

【讨论】:

  • 感谢您的回复,棘手的部分是要比较它是否是社交媒体链接。由于每个网站都有不同的变量来存储社交媒体链接。可以分享一下对比代码吗?这样我可能对我们如何比较有所了解。
【解决方案2】:

对于链接

for link in links:
    if "linkedin" in link:
        print("We found a linked in Link")

一般带有名称列表:

sn_links = ["facebook"] # etc.
for link in links:
    for social in sn_links:
        if social in link:
            print("We found a social Link")

【讨论】:

  • 非常感谢,但我想在 BeautifulSoup 中使用此代码,因为我在 BeautifulSoup 的整个项目中工作
  • @ÂftãbBãlôçh 您可以使用this answer 创建链接列表。然后你就可以使用我的代码了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-18
  • 1970-01-01
  • 2012-12-07
  • 1970-01-01
相关资源
最近更新 更多