【发布时间】:2021-08-09 12:20:23
【问题描述】:
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
import time
def checkLinkedIn(command):
url = f"https://www.linkedin.com/in/{command}"
path = "C:\Program Files (x86)\chromedriver.exe"
options = Options()
options.add_argument("--headless")
driver = webdriver.Chrome(path, options=options)
driver.get(url)
soup = BeautifulSoup(driver.page_source, 'html.parser')
time.sleep(2)
driver.quit()
name = soup.find("h1", attrs={"class": "top-card-layout__title"})
if name:
print("LinkedIn profile found")
print(url)
else:
print("No LinkedIn profile found")
def checkTwitter(command):
url = f"https://www.twitter.com/{command}"
path = "C:\Program Files (x86)\chromedriver.exe"
options = Options()
options.add_argument("--headless")
driver = webdriver.Chrome(path, options=options)
driver.get(url)
soup = BeautifulSoup(driver.page_source, 'html.parser')
time.sleep(2)
driver.quit()
at_tag = soup.find("div", attrs={"dir": "ltr"})
print(soup.text)
if at_tag:
print("Twitter profile found")
print(url)
else:
print("No Twitter profile found")
usrname = input("--> ")
checkTwitter(usrname)
LinkedIn 功能有效。然而,Twitter 提出了这个:
JavaScript 不可用。 我们检测到此浏览器中禁用了 JavaScript。请启用 JavaScript 或切换到支持的浏览器以继续使用 twitter.com。您可以在我们的帮助中心查看支持的浏览器列表。
如何在无头 Chrome 中启用 Javascript?提前致谢。
【问题讨论】:
标签: javascript python selenium beautifulsoup twitter