Python 如何使用selenium web驱动程序刮取网站而不被阻止
我正在抓取此页面,但每次浏览器未加载页面或无法访问网站时。我如何解决这个问题Python 如何使用selenium web驱动程序刮取网站而不被阻止,python,selenium,web-scraping,proxy,ip,Python,Selenium,Web Scraping,Proxy,Ip,我正在抓取此页面,但每次浏览器未加载页面或无法访问网站时。我如何解决这个问题 class SuperSpider(scrapy.Spider): name = 'super' allowed_domains = ['www.elcorteingles.es/supermercado'] start_urls = ['https://www.elcorteingles.es/supermercado/alimentacion-general/'] def __init__(self):
class SuperSpider(scrapy.Spider):
name = 'super'
allowed_domains = ['www.elcorteingles.es/supermercado']
start_urls = ['https://www.elcorteingles.es/supermercado/alimentacion-general/']
def __init__(self):
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_path = which("chromedriver")
driver = webdriver.Chrome(executable_path=chrome_path)
driver.get("https://www.elcorteingles.es/supermercado/alimentacion-general/")
driver.maximize_window()
time.sleep(25)
self.html = driver.page_source
driver.close()
def parse(self, response):
pass
这应该可以绕过机器人检测,但要注意驱动程序的页面来源非常庞大。您可以向我们提供您的代码吗?当然可以,但在代码中您是否尝试过设置用户代理?该网站似乎有某种浏览器验证(页面加载前5秒)是的,我不知道如何使用设置用户代理selenium@Usamahasan参考:非常感谢,现在它可以工作了
from fake_useragent import UserAgent
ua = UserAgent()
a = ua.random
user_agent = ua.random
print(user_agent)
options.add_argument(f'user-agent={user_agent}')
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_argument('--headless')
options.add_argument("--window-size=1920,1080")
#your code
time.sleep(30)
print(driver.page_source)