在不更改网址的网络中进行爬网

时间:2019-09-01 07:43:09

标签: python database web-scraping

我需要进行一些度量,但是在我需要从该网站“ https://www.dubailand.gov.ae/English/RealEstateTransaction/Pages/Daily-Transactions.aspx”提取数据之前,我知道如何进行网络抓取,但是当网站更改url时(意思是,我编写了一个保存所有内容的代码我要提取的网址,然后我一一提取它们)。但是在这里,当我想提取2005年至2019年(逐日)的销售数据(在“过程类型”中有选项“出售”)到“土地交易”,“建筑物交易”,“单位交易”。如果您看到的话,当您更改日期时,URL是相同的...我不知道该怎么做?我的意思是也许含硒,但这要花我大约一年的时间。 谢谢大家

那是我尝试过的方法,但是不起作用,花了我很多时间来提取

from selenium import webdriver
import time
import subprocess
from selenium.webdriver.common.keys import Keys
import time
from random import shuffle
from random import randrange, choice
from selenium.common.exceptions import NoSuchElementException
import random
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By

url= "https://www.dubailand.gov.ae/English/RealEstateTransaction/Pages/Daily-Transactions.aspx"


if(url.rstrip() == repr(url.rstrip())):
    pass
else:
#print(repr(target+text.rstrip()))
    driver = webdriver.Firefox(executable_path='/home/datrick/Desktop/geckodriver')
    driver.get(url)
    driver.implicitly_wait(10)  
    #loging = driver.find_element_by_xpath('//*[@id="link_profile"]').click()
    #driver.implicitly_wait(10)
    try:
        sales = driver.find_element_by_xpath('/html/body/form/div[12]/div[2]/div[2]/div[2]/div[3]/div[1]/div[2]/div/div/div[2]/div/div/div/div[2]/div[1]/div/div/table/tbody/tr[2]/td[2]/select/option[2]').click()
        driver.implicitly_wait(10)
    except:
        time.sleep(5)
    try:
        clickendata = driver.find_element_by_xpath('//*[@id="txtDate"]').click()
        driver.implicitly_wait(10)
    except:
        time.sleep(5)
    try:
        clickenmonth2009 = driver.find_element_by_xpath('/html/body/div[6]/div/div/select[2]/option[1]').click()
        driver.implicitly_wait(10)
    except:
        time.sleep(5)
    try:
        clickenmonth2005 = driver.find_element_by_xpath('/html/body/div[6]/div/div/select[2]/option[7]').click()
        driver.implicitly_wait(10)
    except:
        time.sleep(5)

0 个答案:

没有答案
相关问题