【发布时间】:2018-07-19 16:34:44
【问题描述】:
我正在使用 Python 3.6 和 Beautiful Soup 制作爬虫。这是我的代码
当我运行它时,我得到 element not found 异常,为什么?我想要做的是选择 uri 并单击名称 uri 以便打开一个新页面
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
import re
import pandas as pd
import os
url = "https://www.codechef.com/ratings/all?order=asc&page=3&sortBy=global_rank"
# create a new Firefox session
driver = webdriver.Firefox()
driver.get(url)
soup_level1=BeautifulSoup(driver.page_source, 'lxml')
datalist = [] #empty list
x = 488
for link in soup_level1.find_all('a', id=re.compile(r"^ember")):
elemnt2222=driver.find_element_by_xpath("//*[@id='ember"+str(493)+"']/td[2]/div[2]/a")
python_button = elemnt2222
python_button.click() #click link
【问题讨论】:
标签: python-3.x beautifulsoup web-crawler