Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.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
Python 2.7 ';多行语句中的EOF';在Python中使用Firefox和Selenium连接时出现错误消息_Python 2.7_Firefox_Selenium_Raspberry Pi_Tor - Fatal编程技术网

Python 2.7 ';多行语句中的EOF';在Python中使用Firefox和Selenium连接时出现错误消息

Python 2.7 ';多行语句中的EOF';在Python中使用Firefox和Selenium连接时出现错误消息,python-2.7,firefox,selenium,raspberry-pi,tor,Python 2.7,Firefox,Selenium,Raspberry Pi,Tor,我正在尝试使用python在selenium上使用Firefox和tor。我是用树莓皮做的。目标是让Tor从每次X搜索开始(在这种情况下为4)。我尝试在多进程中这样做。当我不使用FirefoxProfile时,一切正常。但是,当我设置配置文件时,会收到以下消息: 标记输入文件时发生意外错误 /usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.pyc 以下回溯可能已损坏或在错误消息中无效

我正在尝试使用python在selenium上使用Firefox和tor。我是用树莓皮做的。目标是让Tor从每次X搜索开始(在这种情况下为4)。我尝试在多进程中这样做。当我不使用FirefoxProfile时,一切正常。但是,当我设置配置文件时,会收到以下消息:

标记输入文件时发生意外错误 /usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.pyc 以下回溯可能已损坏或在错误消息中无效 is:(‘多行语句中的EOF’,(7,0))

我真的不明白为什么。。。有人有解决办法吗

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import WebDriverException
from selenium.common.exceptions import InvalidSelectorException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from pyvirtualdisplay import Display
from stem.util import term
import stem.process
import multiprocessing
from joblib import Parallel, delayed


start=1000
end=1004
port_tor= 9050
SOCKS_PORT = port_tor
nb_core=4


profile = webdriver.FirefoxProfile()
profile.set_preference('network.proxy.type', 5)
profile.set_preference('network.proxy.socks', '127.0.0.1')
profile.set_preference('network.proxy.socks_port', port_tor)

def fonc1(x)
    display= Display(visible=0,size=(800,600))
    display.start()
    driver = webdriver.Firefox(profile)
    driver.get("https://check.torproject.org/")
    elem4=driver.page_source
    driver.quit()

def fonc2(y):

    print term.format("Starting Tor:\n", term.Attr.BOLD)

    tor_process = stem.process.launch_tor_with_config(
      config = {
        'SocksPort': str(SOCKS_PORT),
      },
       init_msg_handler = print_bootstrap_lines,
    )
    results = Parallel(n_jobs=nb_core)(delayed(fonc1)(i) for i in inputs)
    tor_process.kill()


while start<end:
    inputs=[]
    count=0
    while count<4:
            inputs.append(start)
            count=count+1
            start=start+1
   fonc2(inputs)
从selenium导入webdriver
从selenium.common.exceptions导入TimeoutException
从selenium.webdriver.support.ui导入WebDriverWait
从selenium.common.exceptions导入WebDriverException
从selenium.common.Exception导入InvalidSelectorException
从selenium.webdriver.common.by导入
从selenium.webdriver.support将预期的_条件导入为EC
从selenium.webdriver.firefox.firefox\u配置文件导入FirefoxProfile
从selenium.webdriver.common.desired_功能导入DesiredCapabilities
从pyvirtualdisplay导入显示
来自stem.util导入术语
进口干法
导入多处理
从joblib并行导入,延迟
开始=1000
结束=1004
端口号=9050
SOCKS\u PORT=PORT\u tor
nb_芯=4
profile=webdriver.FirefoxProfile()
profile.set_首选项('network.proxy.type',5)
profile.set_首选项('network.proxy.socks','127.0.0.1')
profile.set_首选项('network.proxy.socks_port',port_tor)
def fonc1(x)
显示=显示(可见=0,大小=(800600))
display.start()
driver=webdriver.Firefox(配置文件)
驱动程序。获取(“https://check.torproject.org/")
elem4=driver.page\u源
driver.quit()
def fonc2(y):
打印term.format(“起始Tor:\n”,term.Attr.BOLD)
tor_进程=stem.process.launch_tor_与配置(
配置={
“SocksPort”:str(SOCKS_端口),
},
init_msg_handler=print_bootstrap_行,
)
结果=并行(n_作业=nb_核心)(输入中i延迟(fonc1)(i)
tor_进程kill()
开始时