无法从xpath的特定网站打印出来// * [@ class =“footballmaincontent”],谢谢!
# -*- coding:UTF-8 -*-
from pyvirtualdisplay import Display
import sys
from bs4 import BeautifulSoup
from selenium import webdriver
display = Display(visible=0, size=(1024, 768))
display.start()
driver = webdriver.Firefox()
driver.get("url")
soup = BeautifulSoup(driver.page_source.encode('utf-8'),'html.parser')
lines = soup.find_elements_by_xpath('//*[@class="footballmaincontent"]/tr')
print lines
driver.close()
display.stop()
答案 0 :(得分:1)
bs4
没有像find_elements_by_xpath()
这样的方法 - 它的Selenium方法。
尝试以下代码:
lines = [event.text for event in driver.find_elements_by_xpath('//*[@class="footballmaincontent"]//tr')]
print lines