HTML 可能不区分大小写,但 XML(以及因此的 XPath)是:“STRONG”与“strong”不同,在您链接到的 HTML 中,只有“strong”。
检索您感兴趣的文本的有用 XPath 表达式可能是
//div[@class="medium-8 columns"]/p[following-sibling::p/strong]/text()
意思是
//div select all `div` elements, anywhere in the document
[@class="medium-8 columns"] but only if they have a `class` attribute whose value is
equal to "medium-8 columns"
/p of those `div` elements select all `p` child elements
[following-sibling::p/strong] but only if they have a following sibling `p` which has a
`strong` element as a child
/text() of the remaining `p` elements, select the text content
哪个会返回(由------分隔的单个结果):
Tim Bajarin is recognized as one of the leading industry
consultants, analysts and futurists, covering the field of
personal computers and consumer technology. Mr. Bajarin has
been with Creative Strategies since 1981 and has served as a
consultant to most of the leading hardware and software
vendors in the industry including IBM, Apple, Xerox, Hewlett
Packard/Compaq, Dell, AT&T, Microsoft, Polaroid, Lotus,
Epson, Toshiba and numerous others.
-----------------------
His articles and/or analysis have appeared in USA Today, Wall
Street Journal, The New York Times, Time and Newsweek
magazines, BusinessWeek and most of the leading business and
trade publications. He has appeared as a business analyst
commenting on the computer industry on all of the major
television networks and was a frequent guest on PBS’ The
Computer Chronicles.
-----------------------
Mr. Bajarin has been a columnist for US computer industry
publications such as PC Week and Computer Reseller News and
wrote for ABCNEWS.COM for two years and Mobile Computing for
10 years. His columns currently appear in Asia Computer
Weekly, Personal Computer World (UK), and Microscope (UK) as
well as Mobile Enterprise Magazine. His various columns and
analyses are syndicated in over 30 countries.
对于你的第二种情况:
这里我需要提取“Further History”之后的段落文本(不包括“Further History”)
只需将路径表达式中的following-sibling 替换为preceding-sibling。