小编par*_*rik的帖子

如何修复Selenium WebDriverException:"浏览器似乎已退出"

当我想使用时,我得到了这个例外 FireFox webdriver

引发WebDriverException"浏览器似乎已退出"WebDriverException:消息:在我们连接之前,浏览器似乎已退出.如果在FirefoxBinary构造函数中指定了log_file,请检查它是否有详细信息.

我读了这个问题并更新了我的硒,但我已经遇到了同样的问题.

我的代码:

driver = webdriver.Firefox()
time.sleep(5)
driver.get('http://www.example.com')
Run Code Online (Sandbox Code Playgroud)

UPDATE

我读了这个问题

现在我有这个错误

OSError: [Errno 20] Not a directory
Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x407a690>> ignored
Run Code Online (Sandbox Code Playgroud)

python selenium selenium-firefoxdriver selenium-webdriver

5
推荐指数
2
解决办法
9110
查看次数

如何防止在刮取亚马逊时被列入黑名单

我试图通过Scrapy刮掉亚马逊.但我有这个错误

DEBUG: Retrying <GET http://www.amazon.fr/Amuses-bouche-Peuvent-b%C3%A9n%C3%A9ficier-dAmazon-Premium-Epicerie/s?ie=UTF8&page=1&rh=n%3A6356734031%2Cp_76%3A437878031> 
(failed 1 times): 503 Service Unavailable
Run Code Online (Sandbox Code Playgroud)

我认为这是因为=亚马逊非常擅长检测机器人.我该如何防止这种情况?

time.sleep(6)在每次请求之前使用 过.

我不想使用他们的API.

我试过用tor和polipo

amazon web-crawler scrapy web-scraping scrapy-spider

4
推荐指数
1
解决办法
6765
查看次数

Selenium在Python-Scrapy中执行Js的替代方法是什么?

我想在Python-Scrapy中执行JavaScript的功能,之前我使用的是Selenium,但是Selenium对于抓取大型网站来说太慢了.

我想知道什么是硒在Scrapy中执行js的最佳选择?

python selenium scrapy web-scraping

4
推荐指数
1
解决办法
1790
查看次数

如何使用Splash与python请求?

我想在请求中使用splash ,就像这样

requests.post(myUrl,headers=myHeaders, data=payload, meta={
                                        'splash': {
                                            'endpoint': 'render.html',
                                            'args': {'wait': 1}
                                            }
                                        })
Run Code Online (Sandbox Code Playgroud)

但我有这个错误

TypeError: request() got an unexpected keyword argument 'meta'
Run Code Online (Sandbox Code Playgroud)

我知道这与scrapy.Request有关,但我想用于请求

splash-screen scrapy python-2.7 python-requests scrapyjs

2
推荐指数
1
解决办法
4400
查看次数

如何忽略 Selenium 中的异常?

我使用Python Selenium抓取网站,但我的爬虫因异常而停止:

StaleElementReferenceException:消息:过时的元素引用:元素未附加到页面文档

即使元素未附加,我如何继续爬行?

更新

我将我的代码更改为:

try:
    libelle1 = prod.find_element_by_css_selector('.em11')
    libelle1produit = libelle1.text  # libelle1 OK
    libelle1produit = libelle1produit.decode('utf-8', 'strict')
except StaleElementReferenceException:
    pass
Run Code Online (Sandbox Code Playgroud)

但我有这个例外

NoSuchElementException: Message: no such element
Run Code Online (Sandbox Code Playgroud)

我也尝试过这个:

try:
    libelle1 = prod.find_element_by_css_selector('.em11')
    libelle1produit = libelle1.text  # libelle1 OK
    libelle1produit = libelle1produit.decode('utf-8', 'strict')
except :
    pass
Run Code Online (Sandbox Code Playgroud)

python selenium web-crawler web-scraping selenium-webdriver

2
推荐指数
2
解决办法
9655
查看次数

如何使用Python将此字符串转换为iso 8601

我有这个字符串

14 Mai 2014
Run Code Online (Sandbox Code Playgroud)

我想将其转换为iso 8601

我读了这个答案这个

首先我尝试将字符串转换为日期,然后将其转换为 iso 格式:

test_date = datetime.strptime("14 Mai 2014", '%d %m %Y')
iso_date = test_date.isoformat()
Run Code Online (Sandbox Code Playgroud)

我收到这个错误

ValueError: time data '14 Mai 2014' does not match format '%d %m %Y'
Run Code Online (Sandbox Code Playgroud)

python datetime iso8601

2
推荐指数
1
解决办法
5926
查看次数

你如何更快地制作硒脚本?

我使用python Selenium和Scrapy来抓取一个网站.

但我的剧本很慢,

Crawled 1 pages (at 1 pages/min)
Run Code Online (Sandbox Code Playgroud)

我使用CSS SELECTOR而不是XPATH来优化时间.我改变了中间件

'tutorial.middlewares.MyCustomDownloaderMiddleware': 543,
Run Code Online (Sandbox Code Playgroud)

是Selenium太慢还是我应该在Setting中改变一些东西?

我的代码:

def start_requests(self):
    yield Request(self.start_urls, callback=self.parse)
def parse(self, response):
    display = Display(visible=0, size=(800, 600))
    display.start()
    driver = webdriver.Firefox()
    driver.get("http://www.example.com")
    inputElement = driver.find_element_by_name("OneLineCustomerAddress")
    inputElement.send_keys("75018")
    inputElement.submit()
    catNums = driver.find_elements_by_css_selector("html body div#page div#main.content div#sContener div#menuV div#mvNav nav div.mvNav.bcU div.mvNavLk form.jsExpSCCategories ul.mvSrcLk li")
    #INIT
    driver.find_element_by_css_selector(".mvSrcLk>li:nth-child(1)>label.mvNavSel.mvNavLvl1").click()
    for catNumber in xrange(1,len(catNums)+1):
        print "\n IN catnumber \n"
        driver.find_element_by_css_selector("ul#catMenu.mvSrcLk> li:nth-child(%s)> label.mvNavLvl1" % catNumber).click()
        time.sleep(5)
        self.parse_articles(driver)
        pages = driver.find_elements_by_xpath('//*[@class="pg"]/ul/li[last()]/a')

        if(pages):
            page = driver.find_element_by_xpath('//*[@class="pg"]/ul/li[last()]/a')

            checkText = …
Run Code Online (Sandbox Code Playgroud)

python selenium middleware scrapy web-scraping

1
推荐指数
1
解决办法
1633
查看次数

Python 中 substr 和 strpos 的 PHP 等价物

我尝试将此php函数转换为Python

function trouveunebrique($contenu, $debut, $fin) {
  $debutpos = strpos($contenu, $debut);
  $finpos = strpos($contenu, $fin, $debutpos);
  if ($finpos == 0) {
    $finpos = strlen($contenu);
  }
  $nbdebut = strlen($debut);
  if ($debutpos > 0) {
    $trouveunebrique = substr($contenu, ($debutpos + $nbdebut), ($finpos - $debutpos - $nbdebut));
  } 
  else {
    $trouveunebrique = "";
  }

  return (trim($trouveunebrique));
}
Run Code Online (Sandbox Code Playgroud)

在这里搜索但找不到解决方案。我也试过这个:

   def trouveunebrique(contenu, debut, fin)
        debutpos = haystack.find(contenu, debut)
        finpos = haystack.find(contenu, fin)
        if (finpos == 0)
            finpos = …
Run Code Online (Sandbox Code Playgroud)

php python substring strpos python-2.7

0
推荐指数
1
解决办法
2017
查看次数