<?php
$feed = file_get_contents('http://thexmofo.wordpress.com/feed/');
$xml = new SimpleXMLElement($feed);
$xml->registerXPathNamespace('media', 'http://thexmofo.wordpress.com/feed/');
$images = $xml->xpath('/rss/channel/item/media:content@url');
var_dump($images);
?>
Can anyone tell my why I’m getting Warning: SimpleXMLElement::xpath() [simplexmlelement.xpath]: Invalid expression
followed by bool(false)
?
Josh Davis
28.3k5 gold badges52 silver badges67 bronze badges
asked Mar 10, 2010 at 1:36
That XPath expression is invalid, that much we know. Now since you didn’t say what you were trying to select, all we can do is randomly guess your intentions, so here’s my random guess:
/rss/channel/item/media:content/@url
…assuming you’re trying to select all the @url attributes in that feed.
answered Mar 10, 2010 at 2:31
Josh DavisJosh Davis
28.3k5 gold badges52 silver badges67 bronze badges
1
Well, bool(false)
is probably from your var_dump
.
Iam not sure if media:content@url
is valid xpath…
answered Mar 10, 2010 at 2:10
Phil RykoffPhil Rykoff
12k3 gold badges39 silver badges63 bronze badges
Actually, we are getting invalid xpath expression on loading xsl file.
invalid xpath expression issue getting from below xsl script
1. "<xsl:if test='z:row[index() $gt$ 5]'>"
2. "<xsl:if test="//CICOUNT[@HASARCHIVE = 'Y' or @HASUNREVIEWED = 'Y']">"
3. "<xsl:if test="//CICOUNT[@HASARCHIVE = 'Y' and @HASUNREVIEWED = 'N']">"
4. "<xsl:template match="z:row[index() $lt$ 6]">"
Above issue we are getting because we modifying the old old Microsoft WD-xsl language which was introduced in IE4 in 1998.
Thanks in advance
asked Apr 11, 2017 at 17:58
2
There are several issues with those XPath expressions, including
z
namespace prefix may not have been declared, depending upon
context.index()
is an unknown function; may wantposition()
instead.$gt$
and$lt$
are unknown operators; use>
and<
.
answered Apr 11, 2017 at 18:08
kjhugheskjhughes
105k26 gold badges177 silver badges236 bronze badges
2
|
|||
breezee
16.01.16 — 23:29 |
Как работать с html документом — как его полностью прочитать, или хотя бы как скопировать весь текст из него и работать как со строкой? Подскажите, где методическую информацию взять, в СП нет такого. Там 3 метода без общего примера. |
||
arccos6pi
1 — 16.01.16 — 23:34 |
(0) ЧтениеHTML + ПостроительDOM |
||
breezee
2 — 17.01.16 — 00:35 |
Не могу найти примеры как обходить ДеревоDOM |
||
breezee
3 — 17.01.16 — 00:36 |
Да, платформа 8.3 |
||
breezee
4 — 17.01.16 — 00:44 |
ап |
||
breezee
5 — 17.01.16 — 00:57 |
Обход = обДокументHTML.СоздатьОбходДерева(обДокументHTML.Тело); Я как-то неправильно понял как осуществить обход? У мня весь текст в 1 узле, без разбития по тегам. В общем — можно как-то получить весь тест из html документа — с тегами и прочим? Просто так, как если бы его открыть в текстовом редакторе? |
||
Asmody
6 — 17.01.16 — 00:57 |
http://catalog.mista.ru/public/386307/ |
||
Asmody
7 — 17.01.16 — 00:59 |
Как получить ДокументDOM из HTML — страницы? |
||
breezee
8 — 17.01.16 — 01:10 |
(7) |
||
Asmody
9 — 17.01.16 — 01:14 |
(8) Код из (7) работает: я так отчеты мегафоновские разбираю. |
||
breezee
10 — 17.01.16 — 01:20 |
(9) Ок, в любом случае мне проще строкой. У меня цикл по всем классам, потом вложенный по элементам класса и нужно отдельно выделить элемент, выделенный <b></b> HTML я так понял выглядит не так как её себе представлял — т.е. это не текст с тегами классов и прочими тегами, а каки-то узлы. В общем -проще работать со строкой текста из HTML, вот только как её получить я не понимаю |
||
breezee
11 — 17.01.16 — 01:34 |
Пишет |
||
Asmody 12 — 17.01.16 — 01:52 |
(11) Неправильно. |
TurboConf — расширение возможностей Конфигуратора 1С
Certain xpath expressions that are valid in, say, Selenium (and most other xpath tools I’ve used) seem to cause the following error (about a hundred times, I’m assuming each time capybara runs the call until the wait timer runs out) when using webkit — Since I’ve been trying to switch all my Selenium tests over to webkit, this is a bit of an issue:
INVALID_EXPRESSION_ERR: DOM XPath Exception 51: The expression had a syntax error or otherwise is not a legal expression according to the rules of the specific XPathEvaluator.
As an example, when checking from a particular element, for example, the title
title=session.find("//title")
title.has_xpath?(".//[contains(text(),'whatever')]")
causes the error (without any helpful notes on which line it occured or the Capybara standard invalid xpath error). Meanwhile,
session.has_xpath("//title/[contains(text(),'whatever')]"
works fine. Obviously there are plenty of ways to work around this, but it did give me a bit of a headache — at the very least the error messages should be a bit more specific as to where it occurred.
Obviously, this may be one of those webkit issues rather than a capybara-webkit issue.
Уведомления
- Начало
- » Python для новичков
- » lxml.etree.XPathEvalError: Invalid expression
#1 Окт. 3, 2014 16:13:28
lxml.etree.XPathEvalError: Invalid expression
В html есть такие строки:
<s class="test"><!--постоянно изменяющийся нужный текст--></s>
Делаю:
test = lxml.html.fromstring(html) test = text.xpath('//s@[class="test"]')
Получаю:
File "lxml.etree.pyx", line 1317, in lxml.etree._Element.xpath (src/lxml/lxml.etree.c:36891) File "xpath.pxi", line 290, in lxml.etree.XPathElementEvaluator.__call__ (src/lxml/lxml.etree.c:103188) File "xpath.pxi", line 212, in lxml.etree._XPathEvaluatorBase._handle_result (src/lxml/lxml.etree.c:102495) File "xpath.pxi", line 198, in lxml.etree._XPathEvaluatorBase._raise_eval_error (src/lxml/lxml.etree.c:102367) lxml.etree.XPathEvalError: Invalid expression
Вот что не так?
Офлайн
- Пожаловаться
#2 Окт. 3, 2014 16:32:16
lxml.etree.XPathEvalError: Invalid expression
test = text.xpath('//s[@class="test"]')
Офлайн
- Пожаловаться
#3 Окт. 3, 2014 16:55:26
lxml.etree.XPathEvalError: Invalid expression
Кстати, почему print выводит такую байду:
[<Element i at 18034c8>, <Element i at 1803530>, <Element i at 1803598>, <Element i at 1803600>, <Element i at 1803668>, <Element i at 18036d0>, <Element i at 1803738>, <Element i at 18037a0>, <Element i at 1803808>, <Element i at 1803870>, <Element i at 18038d8>, <Element i at 1803940>, <Element i at 18039a8>, <Element i at 1803a10>, <Element i at 1803a78>, <Element i at 1803ae0>, <Element i at 1803b48>, <Element i at 1803bb0>, <Element i at 1803c18>, <Element i at 1803c80>]
Везде print переменной “list” выводит нормальный список. Например ссылки отображаются как ссылки.
Офлайн
- Пожаловаться
#4 Окт. 4, 2014 00:54:14
lxml.etree.XPathEvalError: Invalid expression
gelius
Кстати, почему print выводит такую байду:
Какой print?
Офлайн
- Пожаловаться
#5 Окт. 4, 2014 01:14:54
lxml.etree.XPathEvalError: Invalid expression
Когда я собираю ссылки так:
urls = lxml.html.fromstring(html) urls = urls.xpath(u'//img/ancestor::a[not(re:match(@href, "(slovo)")) ]/@href', namespaces={"re": "http://exslt.org/regular-expressions"}) print urls
Выводится список ссылок.
В таком случае:
test = lxml.html.fromstring(html) test = test.xpath('//s@[class="test"]') print test
Отдает вот это:
[<Element s at 18034c8>, <Element s at 1803530>, <Element s at 1803598>, <Element s at 1803600>, <Element s at 1803668>, <Element s at 18036d0>, <Element s at 1803738>, <Element s at 18037a0>, <Element s at 1803808>, <Element s at 1803870>, <Element s at 18038d8>, <Element s at 1803940>, <Element s at 18039a8>, <Element s at 1803a10>, <Element s at 1803a78>, <Element s at 1803ae0>, <Element s at 1803b48>, <Element s at 1803bb0>, <Element s at 1803c18>, <Element s at 1803c80>]
Не понимаю в чем разница, и что делать с таким списком во втором случае.
Офлайн
- Пожаловаться
#6 Окт. 4, 2014 03:07:20
lxml.etree.XPathEvalError: Invalid expression
gelius
test = test.xpath('//s@[class="test"]')
Выше bica написал, куда @ поставить.
@ — at, сокращение от attribute
В квадратных скобках записывается условие, по которому нужно выбирать элементы из всего множества элементов.
test = test.xpath('//s[@class="test"]')
// — на любой глубине
s — элементы с именем s
[ — у которых
@ — атрибут
class — с именем class
= — равен
“test” — строке test
test = test.xpath('//s[@class="test"]/text()')
/ — и у этих элементов
text() — выполнить функцию взятия текста
Офлайн
- Пожаловаться
- Начало
- » Python для новичков
- » lxml.etree.XPathEvalError: Invalid expression