我有这个代码,在第一页上输入一个邮政编码,但我越来越卡在如何刮第二页。我只想收集表单中的所有字段并将其打印到CSV。任何帮助将不胜感激。我尝试使用xpath和element. id。第二个页面有一个动态网址,所以我不能直接引用。
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from bs4 import BeautifulSoup
import requests
chrome_options = Options()
chrome_options.add_argument("start-maximized")
chrome_options.add_argument("disable-infobars")
chrome_options.add_argument("--disable-extensions")
option = webdriver.ChromeOptions()
option.add_experimental_option("detach", True)
driver = webdriver.Chrome(options = option)
driver.get("https://www.thegeneral.com")
element = WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.ID, "free-quote-zip")))
element.click()
element.clear()
element.send_keys("63013")
element.submit()
def click_through_to_new_page(link_text):
link = browser.find_element_by_link_text('my link')
link.click()
def link_has_gone_stale():
try:
# poll the link with an arbitrary call
link.find_elements_by_id('doesnt-matter')
return False
except StaleElementReferenceException:
return True
wait_for(link_has_gone_stale)
results = driver.find_elements(By.XPATH, "//[@id="autoInsurance"]")
print(results)
1条答案
按热度按时间disho6za1#
您可以填写以下表格。