使用selenium(python)抓取网页

使用selenium(python)抓取网页,python,selenium,xpath,web-scraping,Python,Selenium,Xpath,Web Scraping,您好,我想取消在下图中选择的内容: 我知道我可以使用以下代码获取文本: cell = driver.find_elements_by_xpath(".//*[@id='ip_selection1233880116name']") print cell.text 但我的问题是ip_Selection1233880116名称应该是动态的,因为您可以从图像中看到它每次都在变化 我怎么做呢 非常感谢你的帮助 Use contains仅捕获名称,假定数字发生了所有变化,对于单个元素,您还应使用fin

您好,我想取消在下图中选择的内容:

我知道我可以使用以下代码获取文本:

cell = driver.find_elements_by_xpath(".//*[@id='ip_selection1233880116name']") 
print cell.text
但我的问题是ip_Selection1233880116名称应该是动态的,因为您可以从图像中看到它每次都在变化

我怎么做呢


非常感谢你的帮助

Use contains仅捕获名称,假定数字发生了所有变化,对于单个元素,您还应使用
find\u element
,而不是
find\u elements

find_element_by_xpath("//*[contains(@id,'ip_selection') and contains(@id,'name')]") 
根据浏览器的不同,您还可以使用“开始于”和“结束于”:

find_element_by_xpath("//*[starts-with(@id,'ip_selection') and ends-with(@id,'name')]") 

谢谢你是一个伟大的人!!!我不知道我可以用。。。有了这一点,它真的工作得很好:D。。。再次感谢!