Issue
import scrapy
from scrapy.crawler import CrawlerProcess
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.proxy import Proxy, ProxyType
class FooSpider(scrapy.Spider):
name = 'foo'
start_urls = ["https://www.whatismybrowser.com/"]
index=1
def __init__(self, *args, **kwargs):
super(FooSpider, self).__init__(*args, **kwargs)
self.download_delay = 0.25
chrome_options = Options() # Initializing Chrome
#chrome_options.add_argument("--headless")
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument('--ignore-ssl-errors')
IP = '176.31.69.183' # random free proxy from net
PORT = 8080
prox = Proxy()
prox.proxy_type = ProxyType.MANUAL
prox.http_proxy = f'{IP}:{PORT}'
prox.socks_proxy = f'{IP}:{PORT}'
prox.ssl_proxy = f'{IP}:{PORT}'
capabilities = webdriver.DesiredCapabilities.CHROME
prox.add_to_capabilities(capabilities)
self.browser = webdriver.Chrome(executable_path="/home/timmy/Downloads/chromedriver",options=chrome_options, desired_capabilities=capabilities)
#self.browser.implicitly_wait(60) #
def parse(self,response):
self.browser.get(response.url)
data= self.random_data()
print(data)
process = CrawlerProcess({'LOG_LEVEL':'INFO',})
process.crawl(FooSpider)
spider = next(iter(process.crawlers)).spider
process.start()
this is the error I am getting
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: cannot parse capability: proxy
from invalid argument: Specifying 'socksProxy' requires an integer for 'socksVersion'
I got the proxy from SSlproxies and I am trying to use it, I am using the answer from this question running-selenium-webdriver-with-a-proxy-in-python but I got the error above
How can I fix?
Solution
You are using old syntax for chrome proxies. This is the method of setting a proxy server with no authentication.
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--proxy-server=http://ipaddress:port')
driver = webdriver.Chrome(chrome_options=chrome_options)
Answered By - ThePyGuy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.