注意:在获得屏幕截图时,目标网站上有数据,该数据不为空。
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
!pip install selenium
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
wd = webdriver.Chrome('chromedriver',options=options)
wd.get('http://arsiv.mackolik.com/Genis-Iddaa-Programi')
import pandas as pd
import time
timestr = time.strftime("%Y%m%d-%H%M%S")
first_team= wd.find_elements_by_xpath('//*[@id="resultsList"]/tbody/tr/td[6]/a')
second_team= wd.find_elements_by_xpath('//*[@id="resultsList"]/tbody/tr/td[7]/a')
my_list1=[]
my_list2=[]
for name in first_team:
print(name.text)
my_list1.append(name.text)
for name in second_team:
print(name.text)
my_list2.append(name.text)
df = pd.DataFrame({
'FIRST TEAM': my_list1,
'SECOND TEAM': my_list2
})
df.to_csv(f'{timestr}.csv')
wd.quit()