报错“The result of the xpath expression is: [object Attr]. It should be an element”
正确
try: temp['host_url'] = node.find_element_by_xpath('./div/div/div/ytd-video-meta-block/div/div/div/yt-formatted-string/a').get_attribute('href') except Exception as e: print(e) try: temp['show_url'] = node.find_element_by_xpath('./div/ytd-thumbnail/a').get_attribute('href') except Exception as e: print(e) try: temp['title'] = node.find_element_by_xpath('./div/div/div[1]/div/h3/a').get_attribute('title') except Exception as e: print(e) try: temp['user'] = node.find_element_by_xpath('./div/div/div/ytd-video-meta-block/div/div/div/yt-formatted-string/a').text except Exception as e:
错误:
try: temp['host_url'] = node.find_element_by_xpath('./div/div/div/ytd-video-meta-block/div/div/div/yt-formatted-string/a/@href') except Exception as e: print(e) try: temp['show_url'] = node.find_element_by_xpath('./div/ytd-thumbnail/a/@href') except Exception as e: print(e) try: temp['title'] = node.find_element_by_xpath('./div/div/div[1]/div/h3/a/@title') except Exception as e: print(e) try: temp['user'] = node.find_element_by_xpath('./div/div/div/ytd-video-meta-block/div/div/div/yt-formatted-string/a/text()') except Exception as e: print(e)