我是否必须显式释放/取消绑定套接字才能重用它?我正在考虑使用,close()但我已经看到了一些选项,例如tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1). 我必须使用它还是就close()足够了?
有什么方法可以确保该端口可用于新绑定?
TorPorts = {}
def port_setup(workers):
for worker in range(workers):
for i in range(2):
tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcp.bind(('', 0))
port = tcp.getsockname()[1]
print("{0} port {1}, tcp {2}".format(i,port,tcp))
if not TorPorts.has_key(worker):
TorPorts[worker] = {0:{},1:{}}
TorPorts[worker][i] = {"port":port,"tcp":tcp}
# do some programing
# close ports I s this enough?
for thread,ports in TorPorts[0].items():
tcp_port = ports["tcp"]
tcp_port.close()
Run Code Online (Sandbox Code Playgroud) 我想知道启动驱动程序后如何更新/更改硒中的下载位置?
创建配置文件和启动Webdriver期间设置下载目录不是问题。启动webdriver根据数据类型更改目录后出现问题。
例如,-如果dl doc是Word保存在Docs \ Word中-如果dl doc是pdf保存在Docs \ pdf中
这是我的代码
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.dir', os.getcwd())
profile.set_preference("browser.download.folderList", 2)
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/download,application/octet-stream,application/pdf')
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)
driver.delete_all_cookies()
sleep(10)
# this part doesn't work
driver.profile.set_preference('browser.download.dir',"{0}\{1}".format(os.getcwd(),"Docs"))
driver.profile.update_preferences()
Run Code Online (Sandbox Code Playgroud)