大家好!我是编码的新手,我正在尝试使用Selenium和Python 2.7编写一个webcrawler。我还处于早期阶段,但是我在填补网站空白方面遇到了问题。来自联合国的https://comtrade.un.org/data/。我已经尝试检查网页元素并使用不同的方法(find_element_by_id,find_element_by_class,find_element_by_name,send_keys等),但似乎都没有。
到目前为止,这是我的代码:
import selenium.webdriver.support.ui as ui
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
HEADER = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'
BASE_URL = 'https://comtrade.un.org/data/'
def initialize_webdriver():
profile = webdriver.Chrome()
profile.set_preference("general.useragent.override", HEADER)
driver = webdriver.Chrome(profile)
# driver.implicitly_wait(30)
driver.set_window_size(1180, 980)
return driver
def main():
# driver = initialize_webdriver()
driver = webdriver.Chrome()
driver.get(BASE_URL)
for period in driver.find_element_by_class('s2id_periods'):
period.clear()
period.send_keys('2013')
任何人都可以帮助我吗?提前谢谢!