Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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 python chrome Web驱动程序_Python_Selenium_Selenium Webdriver_Webdriver - Fatal编程技术网

Selenium python chrome Web驱动程序

Selenium python chrome Web驱动程序,python,selenium,selenium-webdriver,webdriver,Python,Selenium,Selenium Webdriver,Webdriver,我试图使用selenium从mouser.com网站上获取一些数据,但在搜索栏中发送了一些数据之后。该网站导致访问被拒绝,我需要帮助绕过它。我试着使用一个代理,但都是一样的 您没有在选项中的任何位置使用useragent。您还需要设置javascript和cookies。不要在短时间内发送太多请求。许多网站认为这是一个机器人,并阻止它。我能建议的是在结果出来之后。。你最好做一些活动,比如向下滚动和向上滚动。。在那里等待一段时间,然后尝试新的URL。 import time from openp

我试图使用selenium从mouser.com网站上获取一些数据,但在搜索栏中发送了一些数据之后。该网站导致访问被拒绝,我需要帮助绕过它。我试着使用一个代理,但都是一样的


您没有在选项中的任何位置使用useragent。您还需要设置javascript和cookies。

不要在短时间内发送太多请求。许多网站认为这是一个机器人,并阻止它。我能建议的是在结果出来之后。。你最好做一些活动,比如向下滚动和向上滚动。。在那里等待一段时间,然后尝试新的URL。
import time
from openpyxl import load_workbook
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from fake_useragent import UserAgent

driver = webdriver.Chrome(executable_path='C:/Users/amuri/AppData/Local/Microsoft/WindowsApps/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/site-packages/chromedriver.exe')
driver.implicitly_wait(1)

#def get_comp_type(comp_pn):
url ='https://www.mouser.com/'
driver.get(url)
print(driver.title)
wait = WebDriverWait(driver, timeout=10)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".form-control.headerSearchBox.search-input.js-search-autosuggest.as-input")))
elem = driver.find_element_by_css_selector(".form-control.headerSearchBox.search-input.js-search-autosuggest.as-input")
elem.click()
elem.send_keys("myString")
elem.send_keys(Keys.RETURN)
time.sleep(1)
from selenium.webdriver.chrome.options import Option
options = Options()
from fake_useragent import UserAgent
ua = UserAgent()
user_agent = ua.random
print(user_agent)
options.add_argument(f'user-agent={user_agent}')
driver = webdriver.Chrome(executable_path='C:/Users/amuri/AppData/Local/Microsoft/WindowsApps/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/site-packages/chromedriver.exe',options=options)