当我想使用时,我得到了这个例外 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) 我试图通过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
我想在Python-Scrapy中执行JavaScript的功能,之前我使用的是Selenium,但是Selenium对于抓取大型网站来说太慢了.
我想知道什么是硒在Scrapy中执行js的最佳选择?
我想在请求中使用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有关,但我想用于请求
我使用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) 我有这个字符串
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 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) 我尝试将此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) python ×6
scrapy ×4
selenium ×4
web-scraping ×4
python-2.7 ×2
web-crawler ×2
amazon ×1
datetime ×1
iso8601 ×1
middleware ×1
php ×1
scrapyjs ×1
strpos ×1
substring ×1