python爬虫----XPath
1.知道本节点元素,如何定位到兄弟元素 详情见 博客 XML代码见下 bt1在文档中只出现一次,所以很容易获取到bt1中内容,那怎么根据<td class='bt1'>来获取bt2中的内容 content_title = driver.find_element_by_xpath("//td[@class='bt1']").text # 获取content_title的父节点的哥哥节点 content_subtitle = driver.find_element_by_xpath("//td[@class='bt1']/../following-sibling::tr[1]").text # 获取第二个tr下面td的父节点的弟弟节点 conten_subtitle = driver.find_element_by_xpath("//td[@class='bt1']/../preceding-sibling::tr[1]").text 返回的内容为:高起点高水平推进福州新区建设 尤权于伟国赴福州新区调研 ‘’ 2.元素替换,查找元素位置可以用变量替换字符串 >>> driver.find_element_by_xpath("//*[@id='mp1057136']").click() >>> a='mp1057136' >>> driver.find_element_by_xpath