html =
<span class="title">
<a href="VIDEO HREF" title="title" class="js-pop">title text</a>"
</span>
代码=
class Client(QWebPage):
def __init__(self, url):
self.app = QApplication(sys.argv)
QWebPage.__init__(self)
self.loadFinished.connect(self.on_page_load)
self.mainFrame().load(QUrl(url))
self.app.exec_()
def on_page_load(self):
self.app.quit()
client_response = Client(url)
source = client_response.mainFrame().toHtml()
soup = bs.BeautifulSoup(source, 'lxml')
for link in soup.findAll('a', class_='js-pop'):
href = link.get('href')
print(href)
print(link.text)
我想让它返回href链接和标题文本。
当我运行它时,它会打印出其中包含文本"js-pop“的每个类,并且有多个名为"js-pop”的类不是我想要抓取的类。
我尝试过在selenium中抓取页面,但当我试图在class='js-pop‘上查找href时,它会输出"none“。
我要抓取的元素都有唯一的ID、CSS选择器和xpath
我该如何定位这个元素呢?
https://stackoverflow.com/questions/50683637
复制相似问题