【发布时间】:2020-11-02 00:31:03
【问题描述】:
我是编码新手,因此对于任何新手错误,我深表歉意。
我希望使用 python 和 selenium 从网页中抓取数据。我认为我已经确定了要提取的数据的 xpath,但是当我提取它时,它返回“None”而不是返回数据。
我正在尝试从以下 html 中提取“2001 年 10 月 - 2002 年 1 月”:
<h4 class="pv-entity__date-range t-14 t-black--light t-normal">
<span class="visually-hidden">Dates Employed</span>
<span>Oct 2001 – Jan 2002</span>
</h4>
为此,我运行了以下代码:
sel = Selector(text=driver.page_source)
prev = sel.xpath('.//span[@class = "pv-entity__date-range.t-14.t-black--light.t-normal"][1]').extract_first()
print(prev)
哪些输出:
None
如何从这段 html 中识别“2001 年 10 月 - 2002 年 1 月”?
提前感谢您的帮助!
【问题讨论】: