gpt4 book ai didi

python - 使用selenium在.click()之后获取新的html

转载 作者:行者123 更新时间:2023-12-01 08:08:14 25 4
gpt4 key购买 nike

我正在使用 selenium 单击链接,但无法获取新表。我使用什么代码来检索新页面?

    df_list = []
url = 'https://www.cartolafcbrasil.com.br/scouts/cartola-fc-2018/rodada-1' #+ str(i)
page = requests.get(url)
soup = BeautifulSoup(page.text, 'html.parser')
table = soup.find_all('table')[0]
df = pd.read_html(str(table), encoding="UTF-8")

driver = webdriver.PhantomJS(executable_path = 'C:\\Python27\\phantomjs-2.1.1-windows\\bin\\phantomjs')
driver.get('https://www.cartolafcbrasil.com.br/scouts/cartola-fc-2018/rodada-1')
driver.find_element_by_xpath("/html[1]/body[1]/form[1]/div[1]/div[2]/div[3]/div[1]/div[1]/div[2]/div[1]/div[1]/div[2]/div[1]/div[2]/div[1]/table[1]/tbody[1]/tr[52]/td[1]/table[1]/tbody[1]/tr[1]/td[2]/a[1]").click()



?????
table = soup.find_all('table')[0]
df = pd.read_html(str(table), encoding="UTF-8")

最佳答案

如果我理解你的问题,那就是“如何从我加载的新页面的 driver 对象中获取 HTML”。答案是driver.page_source

driver.find_element_by_xpath("Some crazy shenanigans of an xpath").click()
html_from_page = driver.page_source
soup = bs4.BeautifulSoup(html_from_page, 'html.parser')
# more stuff

关于python - 使用selenium在.click()之后获取新的html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55427399/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com