Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在selenium中使用无头Chrome启用JavaScript_Javascript_Python_Selenium_Beautifulsoup_Twitter - Fatal编程技术网

如何在selenium中使用无头Chrome启用JavaScript

如何在selenium中使用无头Chrome启用JavaScript,javascript,python,selenium,beautifulsoup,twitter,Javascript,Python,Selenium,Beautifulsoup,Twitter,LinkedIn功能可以正常工作。然而,推特一号提出了这样一个问题: JavaScript不可用。 我们检测到此浏览器中禁用了JavaScript。请启用JavaScript或切换到受支持的浏览器以继续使用twitter.com。您可以在我们的帮助中心看到支持的浏览器列表。 如何在无头Chrome中启用Javascript?提前感谢。使用 import requests from bs4 import BeautifulSoup from selenium import webdriver fr

LinkedIn功能可以正常工作。然而,推特一号提出了这样一个问题:

JavaScript不可用。 我们检测到此浏览器中禁用了JavaScript。请启用JavaScript或切换到受支持的浏览器以继续使用twitter.com。您可以在我们的帮助中心看到支持的浏览器列表。

如何在无头Chrome中启用Javascript?提前感谢。

使用

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)
options.add_argument("--enable-javascript")