程序运行2个月都没问题,突然报错,这突如其来的血压飙升` 报错代码如下:
NoSuchElementException Traceback (most recent call last)
<ipython-input-5-71fe1159ea05> in <module>
162
163 elif get_date('/hierarchy/android.widget.FrameLayout/cn.bingoogolapple.swipebacklayout.BGASwipeBackLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[2]/androidx.viewpager.widget.ViewPager/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout[1]/android.widget.LinearLayout/android.widget.RelativeLayout[4]/android.widget.TextView[2]') == stop_date:
--> 164 crawl_page1(1,0)
165 crawl_page2(0)
166
<ipython-input-5-71fe1159ea05> in crawl_page1(in_order, out_order)
31 datalist[out_order].append(title.text)
32
---> 33 element = driver.find_element_by_xpath('/hierarchy/android.widget.FrameLayout/cn.bingoogolapple.swipebacklayout.BGASwipeBackLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[2]/androidx.viewpager.widget.ViewPager/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/androidx.recyclerview.widget.RecyclerView/android.widget.FrameLayout['+str(in_order)+']/android.widget.LinearLayout/android.view.ViewGroup/android.widget.LinearLayout[1]/android.widget.RelativeLayout[2]/android.widget.TextView[3]')
34 datalist[out_order].append(element.text)
35
整个爬虫项目有xpath的地方几乎全部都是 NoSuchElementException: Message: An element could not be located on the page using the given search parameters. 因为我是直接用appium进行元素解析的,xpath都很长很长,也没有仔细比对错误的和调整后的差别,个人猜测是由于app升级造成xpath的轻微改变。 解决方式:重新获取xpath,就搞定了。
|