单击按钮du时遇到问题

2024-10-03 17:15:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我在以下网站(http://www.gamecocksonline.com/sports/m-basebl/sched/scar-m-basebl-sched.html)中遇到了一些问题,当我点击其中一个标题为“更多”的按钮时。下面的错误返回到屏幕上,我将其解释为页脚当前悬停在按钮上是selenium无法单击正确元素的原因。这里有什么解决方法的想法吗(对于selenium来说比较新,但是我使用它来导航到某些页面,我将这些信息提供给BeautifulSoup)?你知道吗

Element <a href="#" class="sch-view-more">...</a> is not clickable at point (1172, 927). Other element would receive the click: <div id="sticky-footer-wrap">...</div>

有没有一个可靠的方法来减轻这个问题,通过滚动网页?你知道吗

回答一些评论:我感兴趣的“更多”链接是那些没有游戏跟踪器链接的链接。你知道吗

迄今为止的代码:

header = {'User-agent' : 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5'}
schedule = 'http://www.gamecocksonline.com/sports/m-basebl/sched/scar-m-basebl-sched.html'
url  = requests.get(schedule, headers = header).text
soup = BeautifulSoup(url, 'html.parser')

events = soup.find_all('tr', {'class': 'event-listing'})
more = soup.find_all('a', {'class': 'sch-view-more'})
status = soup.find_all('td', {'class': 'sch-col-4'})
for idx, (i, j, k) in enumerate(zip(events, more, status)):
    if 'class="sch-gt"' in str(i):
        print(i.find('a', {'class': 'sch-gt'}).get('href'))
        # gametracker(i.find('a', {'class': 'sch-gt'}).get('href'))
    elif k.text!='Cancelled' and k.text!='Postponed':
        os.chdir('C:\Spray Charts')
        options = webdriver.ChromeOptions(); options.add_argument("--start-maximized")
        driver = webdriver.Chrome(chrome_options=options)
        driver.get(schedule)
        python_button = driver.find_elements_by_xpath("//a[@class='sch-view-more']")[idx]
        python_button.click()

Tags: textviewget链接htmlmorefindclass