html = '''<div class="tit_index clearfix">
<h1><p>綠地之窗寫字樓</p><span class="tit_pf"><i>3.67分</i>/5分</span></h1>
</div>'''
xpath1 = ‘//div[@class="tit_index clearfix"]/h1/p’
xpath2 = ‘//div[@class="tit_index clearfix"]/h1’
xpath3= ‘//div[@class="tit_index clearfix"]//p’
講道理,這個xpath1按理說能定位到p標簽啊,但是使用這個路徑就是訪問不了,只能通過相對路徑的xpath3才能訪問到p,
使用xpath2也能定位到h1,但是只要在路徑中加了h1就訪問不了p了。
在使用selenium直接決議這個網站的時候xpath1使用find_element_by_xpath是能定位到p的,我是覺得selenium太慢了,所以能不用就不用
我上邊的html是使用requests獲取的,然后截取的其中一段代碼,該段代碼和selenium獲取到的這段代碼一致
請問大佬們,這是為什么?
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/236210.html
上一篇:求助代碼改寫,謝謝
