所以我已经使用以下代码成功设置了代理,并且一切正常。我想自动将代理导入为字符串并将该字符串添加到下面的 service_args 中,但我不确定如何执行此操作。
当前工作代码:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
proxyIP = ('11.22.33.444')
proxyPort = ('5555')
proxy = ('{}:{}'.format(proxyIP, proxyPort))
service_args = [
'--proxy=11.22.33.44:5555',
'--proxy-type=http',
'--ignore-ssl-errors=true',
]
browser = webdriver.PhantomJS(service_args=service_args)
现在,我希望能够将“proxy”变量传递到“--proxy=11.22.33.44:5555”的位置。我尝试了几种不同的方法但没有运气。有没有人能解决这个问题?
谢谢!
最佳答案
您可以声明不带代理变量的 service_args
,然后将其附加:
service_args = [
'--proxy-type=http',
'--ignore-ssl-errors=true',
]
service_args.append(proxy)
代理需要是一个字符串,因为 service_args
是一个字符串列表。
关于python - 在Python中使用PhantomJS设置代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42216321/