lxml xpath 找不到锚文本

lxml xpath not finding anchor text

我有两个 xpath,其中只有一个正确地从下面的 url 中提取职位。知道为什么 xpath1(我发现它使用 Chrome 的 'inspect element/copy XPath' 功能)不起作用,而 xpath2 起作用吗?

import requests
from lxml import html

url = 'http://www.mynextmove.org/find/browse?c=54'

xpath1 = '//*[@id="content"]/table[1]/tbody/tr/td[1]/a/text()'
xpath2 = '//a[contains(@href, "profile")]/text()'

page = requests.get(url)
tree = html.fromstring(page.text)

jobs = tree.xpath(xpath2)
print 'jobs:', jobs

xpath1 returns[],空列表.

xpath2 returns ['Anthropologists', 'Archeologists', ...]

没有tbody好像改成:

`xpath1 = '//*[@id="content"]/table[1]/tr/td[1]/a/text()'`

试试吧。

这是我这样做时得到的结果:

In [31]: tree.xpath(xpath1)
Out[31]:
['Anthropologists',
 'Archeologists',
 'Architects',
 'Architectural Drafters',
 'Biochemists & Biophysicists',
 'Civil Drafters',
 'Civil Engineers',
 'Environmental Engineering Technicians',
 'Environmental Engineers',
 'Geodetic Surveyors',
 'Lawyers',
 'Legal Secretaries',
 'Mapping Technicians',
 'Marine Architects',
 'Marine Engineers',
 'Paralegals & Legal Assistants',
 'Survey Researchers',
 'Surveying Technicians',
 'Surveyors',
 'Tax Preparers',
 'Transportation Engineers',
 'Veterinarians',
 'Veterinary Assistants & Laboratory Animal Caretakers',
 'Veterinary Technologists & Technicians',
 'Water/Wastewater Engineers']