我正在尝试从网站 https://www.airdna.co抓取数据
我想获得我管理以下代码的第一个建议的价值;问题是我不能点击第一个城市来获取信息有人可以提出解决这个问题的建议吗
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import time
import csv
import unittest
import sys
import datetime
import os.path
import pandas as pd
from datetime import datetime
from selenium import webdriver
from bs4 import NavigableString
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support import expected_conditions
from selenium.common.exceptions import WebDriverException
from bs4 import BeautifulSoup
from bs4.element import Tag
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.remote.errorhandler import ErrorHandler
from unidecode import unidecode
import unicodecsv
class MyTestCase():
def setUp(self):
self.driver = webdriver.Chrome()
#self.driver.error_handler = MyHandler()
def main(self):
REGION=[]
INSEE=[] #la liste des départements
CITIES=[]
with open('3000Commun_France.csv') as csvfile:
csv_reader = csv.reader(csvfile)
next(csv_reader) # supression des entêtes
for row in csv_reader:
REGION.append(row[0])
INSEE.append(row[1])
CITIES.append(row[2])
self.driver = webdriver.Chrome()
driver=self.driver
for insee,city in zip(INSEE,CITIES):
print str(city) +" , "+str(insee)
try:
driver.get("https://www.airdna.co/")
driver.implicitly_wait(20)
driver.find_element_by_css_selector("#searchbox_home").send_keys(city+",FR") # Enter city
# Wait until autosuggestion come and click on first suggestion
condition = EC.visibility_of_element_located((By.CSS_SELECTOR, '#searchbox_home + ul > li:nth-child(1)'))
time.sleep(3)
WebDriverWait(driver, 5).until(condition).click()
page = driver.page_source
soup = BeautifulSoup(page, "lxml")
except NavigableString:
pass
if __name__ == "__main__":
sys.tracebacklimit = 0
MyTestCase().main()