diff --git a/Bachelorarbeit/__init__.py b/Bachelorarbeit/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Bachelorarbeit/__pycache__/__init__.cpython-39.pyc b/Bachelorarbeit/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..99d742a Binary files /dev/null and b/Bachelorarbeit/__pycache__/__init__.cpython-39.pyc differ diff --git a/Bachelorarbeit/__pycache__/settings.cpython-39.pyc b/Bachelorarbeit/__pycache__/settings.cpython-39.pyc new file mode 100644 index 0000000..061297d Binary files /dev/null and b/Bachelorarbeit/__pycache__/settings.cpython-39.pyc differ diff --git a/Bachelorarbeit/data_config.ini b/Bachelorarbeit/data_config.ini new file mode 100644 index 0000000..0ec8c44 --- /dev/null +++ b/Bachelorarbeit/data_config.ini @@ -0,0 +1,87 @@ +[BMBF] +allowed-domain = foerderportal.bund.de +container = //div[@class='detailAnsicht'] +foerderkennzeichen = normalize-space(.//div[@class='detailAnsichtItem']/div[contains(text(),'Förderkennzeichen')]/parent::*/div[2]/text()) +thema = normalize-space(.//div[@class='detailAnsichtItem']/div[contains(text(),'Thema')]/parent::*/div[2]/text()) +verbund = normalize-space(.//div[@class='detailAnsichtItem']/div[contains(text(),'Verbund')]/parent::*/div[2]/form[@id='sucheVerbund']/a/text()) +foerdersumme = normalize-space(.//div[@class='detailAnsichtItem']/div[contains(text(),'Fördersumme')]/parent::*/div[2]/text()) +ressort = normalize-space(.//div[@class='detailAnsichtItem']/div[contains(text(),'Ressort')]/parent::*/div[2]/text()) +projekttraeger = normalize-space(.//div[@class='detailAnsichtItem']/div[contains(text(),'Projektträger')]/parent::*/div[2]/text()) +laufzeit = normalize-space(.//div[@class='detailAnsichtItem']/div[contains(text(),'Laufzeit')]/parent::*/div[2]/text()) +leistungsplansystematik = normalize-space(.//div[@class='detailAnsichtItem']/div[contains(text(),'Leistungsplansystematik')]/parent::*/div[2]/text()) +foerderart = normalize-space(.//div[@class='detailAnsichtItem']/ div[contains(text(),'Förderart')]/parent::*/div[2]/text()) +foerderprofil = normalize-space(.//div[contains(text(),'Förderprofil')]/parent::*/div[2]/text()) +zuwendungsempfaenger = //div[@class='detailAnsichtItem' and @aria-label='Name, Ort, Bundesland und Staat des Zuwendungsempfängers']/child::div[1] +z_empf = normalize-space(./following-sibling::div[1]/text()) +z_empf_ort = normalize-space(./following-sibling::div[3]/text()) +z_empf_Bundesland_stadt = normalize-space(./following-sibling::div[5]/text()) +Ausfuehrende_Stellen = //div[@class='detailAnsichtItem' and @aria-label='Name, Ort, Bundesland und Staat der Ausführenden Stelle']/child::div[1] +a_stelle = normalize-space(./following-sibling::div[1]/text()) +a_stelle_ort = normalize-space(./following-sibling::div[3]/text()) +a_stelle_Bundesland_stadt = normalize-space(./following-sibling::div[5]/text()) + + +[DFG] +allowed-domain = gepris.dfg.de +details_container = //div[@class='content_inside detailed']/div[@class='details'] +title = normalize-space(.//h1[@class='facelift']/text()) +antragsteller = .//div/span[@class='name' and contains(text(), ' Antragsteller')]/parent::*/span[@class='value']/descendant::a/text() +fachliche_Zuordnung = .//div[@class='firstUnderAntragsbeteiligte']/span[@class='value']/text() +foerderung = normalize-space(.//div/span[@class='value' and contains(text(), 'Förderung')]/text()) +Projektkennung = normalize-space(.//div[@class='projektnummer']/span[@class='value']/text()) +Website = .//div//span[@class='value']/a[@title='Webseite' and @class='extern']/@href +beschreibung_container = //div[@class='content_frame']/div[@id='projektbeschreibung'] +project_text = normalize-space(.//div[@id='projekttext']/text()) +DFG_Verfahren = normalize-space(.//div/span[contains(text(),' DFG-Verfahren')]//parent::*/span[2]/text()) +geraetegruppe = normalize-space(.//div/span[contains(text(),' Gerätegruppe')]//parent::*/span[2]/text()) +grossgereate = normalize-space(.//div/span[contains(text(),'Großgeräte')]//parent::*/span[2]/text()) +antragstellende_Institution = normalize-space(.//div/span[contains(text(),'Antragstellende Institution')]//parent::*/span[2]/a/text()) +leiter = normalize-space(.//div/span[contains(text(),'Leiter')]//parent::*/span[2]/a/text()) +mitverantwortliche = .//div/span[contains(text(),'Mitverantwortliche')]//parent::*/span[2]/a[@class='intern']/text() +beteiligte_Person = .//div/span[contains(text(),' Beteiligte Person')]//parent::*/span[2]/descendant::a[@class='intern']/text() +teilprojekt_zu = .//div/span[contains(text(),'Teilprojekt zu')]//parent::*/span[2]/descendant::a[@class='intern']/text() +kooperationspartner = .//div/span[contains(text(),' Kooperationspartner')]//parent::*/span[2]/descendant::a[@class='intern']/text() +internationaler_Bezug = normalize-space(.//div/span[contains(text(),'Internationaler Bezug')]//parent::*/span[2]/text()) +Sprecher = .//div/span[contains(text(),' Sprecher')]//parent::*/span[2]/descendant::a[@class='intern']/text() +beteiligte_Institution = .//div/span[contains(text(),' Beteiligte Institution')]//parent::*/span[2]/child::*/text() +beteiligte_Hochschule = .//div/span[contains(text(),' Beteiligte Hochschule')]//parent::*/span[2]/descendant::a/text() +mitantragstellende_Institution= normalize-space(.//div/span[contains(text(),' Mitantragstellende Institution')]//parent::*/span[2]/descendant::a/text()) +beteiligte_Wissenschaftler = .//div/span[contains(text(),' beteiligte Wissenschaftlerinnen / beteiligte Wissenschaftler')]//parent::*/span[2]/descendant::a[@class='intern']/text() +IGK_Partnerinstitution = normalize-space(.//div/span[contains(text(),' IGK-Partnerinstitution')]//parent::*/span[2]/a[@class='intern']/text()) +partnerorganisation = normalize-space(.//div/span[contains(text(),' Partnerorganisation')]//parent::*/span[2]/a[@class='intern']/text()) +gastgeber = .//div/span[contains(text(),' Gastgeber')]//parent::*/span[2]/descendant::a[@class='intern']/text() +anwendungspartner = .//div/span[contains(text(),' Anwendungspartner')]//parent::*/span[2]/descendant::a[@class='intern']/text() +beteiligte_Fachrichtungen = normalize-space(.//div/span[contains(text(),'Beteiligte Fachrichtungen')]//parent::*/span[2]/text()) +ehemalige_Antragsteller = .//div/span[contains(text(),' Ehemalige Antragsteller')]//parent::*/span[2]/descendant::a/text() + +[EU] +title_loading_phase = //div[contains(@class, 'c-header-project__title-container')]/h1[contains(@class, 'c-header-project__title')] +title = //div[contains(@class, 'c-header-project__title-container')]/h1[contains(@class, 'c-header-project__title')] +content_container_loading_phase = //article +content_container = //article +objective = //h2[contains(text(), ' Objective ')]/parent::*/p[contains(@class, 'c-article__text')] +programme = //h3[contains(text(), 'Programme(s)')]/parent::*/ul/li/a +project_description = //h2[contains(text(), 'Project description')]//parent::*//p[contains(@class, 'c-project-description__text') or contains(@class, 'c-article__text')] +proposal = //h3[contains(text(), 'Call for proposal')]/parent::*/p/span +fields_of_science_list = //h3[contains(text(), 'Fields of science')]/parent::*/ul/li[@class='ng-star-inserted']/child::span[@class='ng-star-inserted'] +fields_of_science = ./a +topics = //h3[contains(text(), 'Topic(s)')]/parent::*/ul/li/a +funding_scheme = //h3[contains(text(), 'Funding Scheme')]/parent::*/a +coordinator = //h3[contains(text(), 'Coordinator')]/parent::*//div[contains(@class, 'c-part-info__title')] +coordinator_address = //h3[contains(text(), 'Coordinator')]/parent::*//div[contains(text(), ' Address ')]/parent::*/div[contains(@class, 'c-part-info__content')] +coordinator_region = //h3[contains(text(), 'Coordinator')]/parent::*//div[contains(text(), 'Region')]/parent::*/div[contains(@class, 'c-part-info__content')] +coordinator_activity_type = //h3[contains(text(), 'Coordinator')]/parent::*//div[contains(text(), 'Activity type')]/parent::*/div[contains(@class, 'c-part-info__content')] +coordinator_net_EU_contribution = //h3[contains(text(), 'Coordinator')]/parent::*//div[contains(text(), 'Net EU contribution')]/parent::*/div[contains(@class, 'c-part-info__content')] +coordinator_other_fundings = //h3[contains(text(), 'Coordinator')]/parent::*//div[contains(text(), 'Other funding')]/parent::*/div[contains(@class, 'c-part-info__content')] +coordinator_link = //h3[contains(text(), 'Coordinator')]/parent::*//div[contains(text(), 'Links')]/parent::*//span/a +project_info_container_loading_phase = //app-project-info//div[@class='c-project-info__content'] +project_info_container = //app-project-info//div[@class='c-project-info__content'] +grant_agreement_ID = //div[contains(text(), 'Grant agreement ID')] +doi = //span[contains(text(), 'DOI')]/parent::*/a +project_acronym = //div[@class='c-project-info__acronym'] +start_date = //span[contains(text(), 'Start date')]/parent::* +end_date = //span[contains(text(), 'End date')]/parent::* +funded_under = //span[contains(text(), 'Funded under')]/parent::*/ul/li +overal_budget = //span[contains(text(), 'Overall budget') or contains(text(), 'Total cost')]/parent::* +EU_contribution = //span[contains(text(), 'EU contribution')]/parent::* + diff --git a/Bachelorarbeit/items.py b/Bachelorarbeit/items.py new file mode 100644 index 0000000..c31a073 --- /dev/null +++ b/Bachelorarbeit/items.py @@ -0,0 +1,12 @@ +# Define here the models for your scraped items +# +# See documentation in: +# https://docs.scrapy.org/en/latest/topics/items.html + +import scrapy + + +class BachelorarbeitItem(scrapy.Item): + # define the fields for your item here like: + # name = scrapy.Field() + pass diff --git a/Bachelorarbeit/middlewares.py b/Bachelorarbeit/middlewares.py new file mode 100644 index 0000000..222fad0 --- /dev/null +++ b/Bachelorarbeit/middlewares.py @@ -0,0 +1,103 @@ +# Define here the models for your spider middleware +# +# See documentation in: +# https://docs.scrapy.org/en/latest/topics/spider-middleware.html + +from scrapy import signals + +# useful for handling different item types with a single interface +from itemadapter import is_item, ItemAdapter + + +class BachelorarbeitSpiderMiddleware: + # Not all methods need to be defined. If a method is not defined, + # scrapy acts as if the spider middleware does not modify the + # passed objects. + + @classmethod + def from_crawler(cls, crawler): + # This method is used by Scrapy to create your spiders. + s = cls() + crawler.signals.connect(s.spider_opened, signal=signals.spider_opened) + return s + + def process_spider_input(self, response, spider): + # Called for each response that goes through the spider + # middleware and into the spider. + + # Should return None or raise an exception. + return None + + def process_spider_output(self, response, result, spider): + # Called with the results returned from the Spider, after + # it has processed the response. + + # Must return an iterable of Request, or item objects. + for i in result: + yield i + + def process_spider_exception(self, response, exception, spider): + # Called when a spider or process_spider_input() method + # (from other spider middleware) raises an exception. + + # Should return either None or an iterable of Request or item objects. + pass + + def process_start_requests(self, start_requests, spider): + # Called with the start requests of the spider, and works + # similarly to the process_spider_output() method, except + # that it doesn’t have a response associated. + + # Must return only requests (not items). + for r in start_requests: + yield r + + def spider_opened(self, spider): + spider.logger.info('Spider opened: %s' % spider.name) + + +class BachelorarbeitDownloaderMiddleware: + # Not all methods need to be defined. If a method is not defined, + # scrapy acts as if the downloader middleware does not modify the + # passed objects. + + @classmethod + def from_crawler(cls, crawler): + # This method is used by Scrapy to create your spiders. + s = cls() + crawler.signals.connect(s.spider_opened, signal=signals.spider_opened) + return s + + def process_request(self, request, spider): + # Called for each request that goes through the downloader + # middleware. + + # Must either: + # - return None: continue processing this request + # - or return a Response object + # - or return a Request object + # - or raise IgnoreRequest: process_exception() methods of + # installed downloader middleware will be called + return None + + def process_response(self, request, response, spider): + # Called with the response returned from the downloader. + + # Must either; + # - return a Response object + # - return a Request object + # - or raise IgnoreRequest + return response + + def process_exception(self, request, exception, spider): + # Called when a download handler or a process_request() + # (from other downloader middleware) raises an exception. + + # Must either: + # - return None: continue processing this exception + # - return a Response object: stops process_exception() chain + # - return a Request object: stops process_exception() chain + pass + + def spider_opened(self, spider): + spider.logger.info('Spider opened: %s' % spider.name) diff --git a/Bachelorarbeit/pipelines.py b/Bachelorarbeit/pipelines.py new file mode 100644 index 0000000..e98f09b --- /dev/null +++ b/Bachelorarbeit/pipelines.py @@ -0,0 +1,13 @@ +# Define your item pipelines here +# +# Don't forget to add your pipeline to the ITEM_PIPELINES setting +# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html + + +# useful for handling different item types with a single interface +from itemadapter import ItemAdapter + + +class BachelorarbeitPipeline: + def process_item(self, item, spider): + return item diff --git a/Bachelorarbeit/settings.py b/Bachelorarbeit/settings.py new file mode 100644 index 0000000..21e55e4 --- /dev/null +++ b/Bachelorarbeit/settings.py @@ -0,0 +1,93 @@ +# Scrapy settings for Bachelorarbeit project +# +# For simplicity, this file contains only settings considered important or +# commonly used. You can find more settings consulting the documentation: +# +# https://docs.scrapy.org/en/latest/topics/settings.html +# https://docs.scrapy.org/en/latest/topics/downloader-middleware.html +# https://docs.scrapy.org/en/latest/topics/spider-middleware.html + +BOT_NAME = 'Bachelorarbeit' + +SPIDER_MODULES = ['Bachelorarbeit.spiders'] +NEWSPIDER_MODULE = 'Bachelorarbeit.spiders' + + +# Crawl responsibly by identifying yourself (and your website) on the user-agent +#USER_AGENT = 'Bachelorarbeit (+http://www.yourdomain.com)' + +# Obey robots.txt rules +ROBOTSTXT_OBEY = True + +# Configure maximum concurrent requests performed by Scrapy (default: 16) +#CONCURRENT_REQUESTS = 32 + +# Configure a delay for requests for the same website (default: 0) +# See https://docs.scrapy.org/en/latest/topics/settings.html#download-delay +# See also autothrottle settings and docs +#DOWNLOAD_DELAY = 3 +# The download delay setting will honor only one of: +#CONCURRENT_REQUESTS_PER_DOMAIN = 16 +#CONCURRENT_REQUESTS_PER_IP = 16 + +# Disable cookies (enabled by default) +#COOKIES_ENABLED = False + +# Disable Telnet Console (enabled by default) +#TELNETCONSOLE_ENABLED = False + +# Override the default request headers: +#DEFAULT_REQUEST_HEADERS = { +# 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', +# 'Accept-Language': 'en', +#} + +# Enable or disable spider middlewares +# See https://docs.scrapy.org/en/latest/topics/spider-middleware.html +#SPIDER_MIDDLEWARES = { +# 'Bachelorarbeit.middlewares.BachelorarbeitSpiderMiddleware': 543, +#} + +# Enable or disable downloader middlewares +# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html +#DOWNLOADER_MIDDLEWARES = { +# 'Bachelorarbeit.middlewares.BachelorarbeitDownloaderMiddleware': 543, +#} + +# Enable or disable extensions +# See https://docs.scrapy.org/en/latest/topics/extensions.html +#EXTENSIONS = { +# 'scrapy.extensions.telnet.TelnetConsole': None, +#} + +# Configure item pipelines +# See https://docs.scrapy.org/en/latest/topics/item-pipeline.html +#ITEM_PIPELINES = { +# 'Bachelorarbeit.pipelines.BachelorarbeitPipeline': 300, +#} + +# Enable and configure the AutoThrottle extension (disabled by default) +# See https://docs.scrapy.org/en/latest/topics/autothrottle.html +#AUTOTHROTTLE_ENABLED = True +# The initial download delay +#AUTOTHROTTLE_START_DELAY = 5 +# The maximum download delay to be set in case of high latencies +#AUTOTHROTTLE_MAX_DELAY = 60 +# The average number of requests Scrapy should be sending in parallel to +# each remote server +#AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0 +# Enable showing throttling stats for every response received: +#AUTOTHROTTLE_DEBUG = False + +# Enable and configure HTTP caching (disabled by default) +# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings +#HTTPCACHE_ENABLED = True +#HTTPCACHE_EXPIRATION_SECS = 0 +#HTTPCACHE_DIR = 'httpcache' +#HTTPCACHE_IGNORE_HTTP_CODES = [] +#HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage' + +# Set settings whose default value is deprecated to a future-proof value +REQUEST_FINGERPRINTER_IMPLEMENTATION = '2.7' +TWISTED_REACTOR = 'twisted.internet.asyncioreactor.AsyncioSelectorReactor' +FEED_EXPORT_ENCODING = 'utf-8' \ No newline at end of file diff --git a/Bachelorarbeit/spiders/__init__.py b/Bachelorarbeit/spiders/__init__.py new file mode 100644 index 0000000..ebd689a --- /dev/null +++ b/Bachelorarbeit/spiders/__init__.py @@ -0,0 +1,4 @@ +# This package will contain the spiders of your Scrapy project +# +# Please refer to the documentation for information on how to create and manage +# your spiders. diff --git a/Bachelorarbeit/spiders/__pycache__/__init__.cpython-39.pyc b/Bachelorarbeit/spiders/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000..15077ed Binary files /dev/null and b/Bachelorarbeit/spiders/__pycache__/__init__.cpython-39.pyc differ diff --git a/Bachelorarbeit/spiders/__pycache__/project_data.cpython-39.pyc b/Bachelorarbeit/spiders/__pycache__/project_data.cpython-39.pyc new file mode 100644 index 0000000..1b6aa52 Binary files /dev/null and b/Bachelorarbeit/spiders/__pycache__/project_data.cpython-39.pyc differ diff --git a/Bachelorarbeit/spiders/project_data.py b/Bachelorarbeit/spiders/project_data.py new file mode 100644 index 0000000..a423b83 --- /dev/null +++ b/Bachelorarbeit/spiders/project_data.py @@ -0,0 +1,324 @@ +import scrapy +from configparser import ConfigParser +import os +import codecs +import pandas as pd +import time + + +class ProjectDataSpider(scrapy.Spider): + name = 'project-data' + config = ConfigParser() + with codecs.open(os.getcwd() + './Bachelorarbeit/data_config.ini', 'r', encoding='utf-8') as f : + config.read_file(f) + domains = config['DFG']['allowed-domain'] + allowed_domains = [domains] + + def __init__(self, start_urls=None): + super(ProjectDataSpider, self).__init__() + self.start_urls = start_urls.split(',') if start_urls else [] + self.items = [] + + def start_requests(self): + for url in self.start_urls: + # print(url) + yield scrapy.Request(url, callback=self.parse) + + def parse(self, response): + + #config_data = self.config['BMBF'] + + # ----------------------------------- BMBF Project ------------------------------ # + # foerderkennzeichen = '' + # thema = '' + # verbund = '' + # foerdersumme = '' + # ressort = '' + # projekttraeger= '' + # laufzeit = '' + # leistungsplansystematik = '' + # foerderart = '' + # z_empf= '' + # z_empf_ort= '' + # z_empf_Bundesland_stadt = '' + # a_stelle = '' + # a_stelle_ort = '' + # a_stelle_Bundesland_stadt ='' + + # for Detail in response.xpath(config_data['container']): + # try: + # foerderkennzeichen = Detail.xpath(config_data['foerderkennzeichen']).get() + # except: + # pass + + # try: + # thema = Detail.xpath(config_data['thema']).get() + # except: + # pass + + # try: + # verbund = Detail.xpath(config_data['verbund']).get() + # except: + # verbund='Nein' + + # try: + # foerdersumme = Detail.xpath(config_data['foerdersumme']).get() + # except: + # pass + + # try: + # ressort = Detail.xpath(config_data['ressort']).get() + # except: + # pass + + # try: + # projekttraeger = Detail.xpath(config_data['projekttraeger']).get() + # except: + # pass + + # try: + # laufzeit = Detail.xpath(config_data['laufzeit']).get() + # except: + # pass + + # try: + # leistungsplansystematik = Detail.xpath(config_data['leistungsplansystematik']).get() + # except: + # pass + + # try: + # foerderart = Detail.xpath(config_data['foerderart']).get() + # except: + # pass + + # try: + # foerderprofil = Detail.xpath(config_data['foerderprofil']).get() + # except: + # pass + + # zuwendungsempfaenger = Detail.xpath(config_data['zuwendungsempfaenger']) + # for za in zuwendungsempfaenger: + # z_empf = za.xpath(config_data['z_empf']).get() + # z_empf_ort = za.xpath(config_data['z_empf_ort']).get() + # z_empf_Bundesland_stadt = za.xpath(config_data['z_empf_Bundesland_stadt']).get() + + # Ausfuehrende_Stellen = Detail.xpath(config_data['Ausfuehrende_Stellen']) + # for stelle in Ausfuehrende_Stellen: + # a_stelle = stelle.xpath(config_data['a_stelle']).get() + # a_stelle_ort = stelle.xpath(config_data['a_stelle_ort']).get() + # a_stelle_Bundesland_stadt = stelle.xpath(config_data['a_stelle_Bundesland_stadt']).get() + + + # item = { + # 'Thema': thema, + # 'Förderkennzeichen': foerderkennzeichen, + # 'Verbund': verbund, + # 'Fördersumme' : foerdersumme, + # 'Ressort' : ressort, + # 'Projektträger': projekttraeger, + # 'Laufzeit': laufzeit, + # 'Leistungsplansystematik': leistungsplansystematik, + # 'Förderart': foerderart, + # 'Förderprofil': foerderprofil, + # 'Zuwendungsempfänger': [z_empf, z_empf_ort, z_empf_Bundesland_stadt], + # 'Ausführende Stellen': [a_stelle, a_stelle_ort, a_stelle_Bundesland_stadt] + + # } + # self.items.append(item) + + # df = pd.DataFrame(self.items) + # df.to_json('BMBF_all_data.json', orient='records', force_ascii=False) + +# ------------------------------------------------------------------------------------------- # +# ------------------------------------- DFG Project ------------------------------------# + config_data = self.config['DFG'] + title = '' + antragsteller = '' + fachliche_Zuordnung = '' + foerderung = '' + Projektkennung = '' + Website = '' + for Detail in response.xpath(config_data['details_container']): + try: + title = Detail.xpath(config_data['title']).get() + except: + pass + try: + antragsteller = Detail.xpath(config_data['antragsteller']).getall() + except: + pass + try: + fachliche_Zuordnung = Detail.xpath(config_data['fachliche_Zuordnung']).getall() + except: + pass + try: + foerderung = Detail.xpath(config_data['foerderung']).get() + except: + pass + try: + Projektkennung = Detail.xpath(config_data['Projektkennung']).get() + except: + pass + try: + Website = Detail.xpath(config_data['Website']).get() + except: + pass + + project_text = '' + DFG_Verfahren = '' + geraetegruppe = '' + grossgereate = '' + antragstellende_Institution = '' + leiter = '' + mitverantwortliche = '' + beteiligte_Person = '' + teilprojekt_zu = '' + kooperationspartner = '' + internationaler_Bezug = '' + Sprecher = '' + beteiligte_Institution = '' + beteiligte_Hochschule = '' + mitantragstellende_Institution = '' + beteiligte_Wissenschaftler = '' + IGK_Partnerinstitution = '' + partnerorganisation = '' + gastgeber = '' + anwendungspartner = '' + beteiligte_Fachrichtungen = '' + ehemalige_Antragsteller = '' + + for Beschreibung in response.xpath(config_data['beschreibung_container']): + try: + project_text = Beschreibung.xpath(config_data['project_text']).get() + except: + pass + try: + DFG_Verfahren = Beschreibung.xpath(config_data['DFG_Verfahren']).get() + except: + pass + try: + antragstellende_Institution = Beschreibung.xpath(config_data['antragstellende_Institution']).get() + except: + pass + try: + geraetegruppe = Beschreibung.xpath(config_data['geraetegruppe']).get() + except: + pass + try: + grossgereate = Beschreibung.xpath(config_data['grossgereate']).get() + except: + pass + try: + leiter = Beschreibung.xpath(config_data['leiter']).get() + except: + pass + try: + mitverantwortliche = Beschreibung.xpath(config_data['mitverantwortliche']).getall() + except: + pass + try: + beteiligte_Person = Beschreibung.xpath(config_data['beteiligte_Person']).get() + except: + pass + try: + teilprojekt_zu = Beschreibung.xpath(config_data['teilprojekt_zu']).get() + except: + pass + try: + kooperationspartner = Beschreibung.xpath(config_data['kooperationspartner']).get() + except: + pass + try: + internationaler_Bezug = Beschreibung.xpath(config_data['internationaler_Bezug']).getall() + except: + pass + try: + Sprecher = Beschreibung.xpath(config_data['Sprecher']).getall() + except: + pass + try: + beteiligte_Institution = Beschreibung.xpath(config_data['beteiligte_Institution']).get() + except: + pass + try: + beteiligte_Hochschule = Beschreibung.xpath(config_data['beteiligte_Hochschule']).get() + except: + pass + try: + mitantragstellende_Institution = Beschreibung.xpath(config_data['mitantragstellende_Institution']).get() + except: + pass + try: + beteiligte_Wissenschaftler = Beschreibung.xpath(config_data['beteiligte_Wissenschaftler']).getall() + except: + pass + try: + IGK_Partnerinstitution = Beschreibung.xpath(config_data['IGK_Partnerinstitution']).get() + except: + pass + try: + partnerorganisation = Beschreibung.xpath(config_data['partnerorganisation']).get() + except: + pass + try: + gastgeber = Beschreibung.xpath(config_data['gastgeber']).getall() + except: + pass + try: + anwendungspartner = Beschreibung.xpath(config_data['anwendungspartner']).getall() + except: + pass + try: + beteiligte_Fachrichtungen = Beschreibung.xpath(config_data['beteiligte_Fachrichtungen']).getall() + except: + pass + try: + ehemalige_Antragsteller = Beschreibung.xpath(config_data['ehemalige_Antragsteller']).getall() + except: + pass + + + + + item = { + 'Title': title, + 'Antragsteller': antragsteller, + 'Fachliche Zuordnung': fachliche_Zuordnung, + 'Förderung': foerderung, + 'Projektkennung' : Projektkennung, + 'Website' : Website, + 'Projecttext' : project_text, + 'DFG Verfahren' : DFG_Verfahren, + 'Gerätegruppe' : geraetegruppe, + 'Grossgeräte' : grossgereate, + 'Antragstellende Institution' : antragstellende_Institution, + 'Leiter' : leiter, + 'Mitverantwortliche' : mitverantwortliche, + 'Beteiligte Personen' : beteiligte_Person, + 'Teilprojekt zu' : teilprojekt_zu, + 'Kooperationspartner' : kooperationspartner, + 'Internationaler Bezug': internationaler_Bezug, + 'Sprecher' : Sprecher, + 'Beteiligte Institution' : beteiligte_Institution, + 'Beteiligte Hochschule' : beteiligte_Hochschule, + 'Mitantragstellende_Institution' : mitantragstellende_Institution, + 'Beteiligte Wissenschaftler' : beteiligte_Wissenschaftler, + 'IGK Partnerinstitution' : IGK_Partnerinstitution, + 'Partnerorganisation' : partnerorganisation, + 'Gastgeber' : gastgeber, + 'Anwendungspartner': anwendungspartner, + 'Beteiligte Fachrichtungen' : beteiligte_Fachrichtungen, + 'Ehemalige Antragsteller': ehemalige_Antragsteller + + + + + } + + self.items.append(item) + df = pd.DataFrame(self.items) + df.to_json('DFG_all_data.json', orient='records', force_ascii=False) + + + + diff --git a/Projectlinks/links_config.ini b/Projectlinks/links_config.ini index 376b8aa..8e55eed 100644 --- a/Projectlinks/links_config.ini +++ b/Projectlinks/links_config.ini @@ -19,6 +19,7 @@ project = .//div[@class='results']/h2/a next-btn = //div[@id='listennavi']/div[@class='listennaviright']/a[@class='nextactive'] search-box = //input[@id='keywords_criterion'] search-btn = //form[@id='searchform']//button +cookies = //div[@id='c-inr']//div[@id='c-bns']/button[contains(text(), 'Statistische / Analyse-Cookies akzeptieren')] @@ -29,6 +30,7 @@ projects-container = //section[contains(@class, 'c-search__results')] projects-list = //app-card-search[@class='ng-star-inserted'] project = .//a[contains(@class, 'c-card-search__title')] next-btn = //ul[@class='c-pagination__list c-pagination__list--last']/li/a[contains(@class, 'c-pagination__page-link') and contains(@aria-label, 'Goto next page')] +cookies = //app-cookies-consent//div[contains(@class, 'co-cookie-consent__button-container')]/button[contains(text(), 'I accept cookies.')] ; search-box = //input[@id='keywords_criterion'] ; search-btn = //form[@id='searchform']//button diff --git a/Projectlinks/links_extractor.py b/Projectlinks/links_extractor.py index e278bf1..77c03c1 100644 --- a/Projectlinks/links_extractor.py +++ b/Projectlinks/links_extractor.py @@ -1,7 +1,3 @@ -# TODO1: Add cookie handeling ✅ -# TODO2: Find out the right way to serch for ude in EU -# TODO3: test the code with all 3 websites again ✅ - from selenium import webdriver from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager @@ -22,28 +18,26 @@ driver.delete_all_cookies() config = ConfigParser() config.read(os.getcwd() + './links_config.ini') -url = config['BMBF']['start-url'] +url = config['example']['start-url'] driver.get(url) driver.maximize_window() -#############Coockies############## +# ----------------------------- Coockies ---------------------------------- # consent_btn= WebDriverWait(driver,10).until(EC.presence_of_element_located(( - By.XPATH, config['BMBF']['cookies'] - ))) + By.XPATH, config['example']['cookies'] + ))) consent_btn.click() - -##########Finding the search input, Typing : Universität Duisburg-Essen and clicking on the search btn ########### - -search_input = driver.find_element(By.XPATH, config['BMBF']['search-box']) +# ----------------------------- locate search box -> type the search word -> press on search button ---------------------------------- # +search_input = driver.find_element(By.XPATH, config['example']['search-box']) search_input.send_keys("Universität Duisburg-Essen") time.sleep(0.1) -search_btn = driver.find_element(By.XPATH, config['BMBF']['search-btn']) +search_btn = driver.find_element(By.XPATH, config['example']['search-btn']) search_btn.click() -###############Pagination############### +# ----------------------------- Pagination ---------------------------------- # links = [] isNextDisabeled = False @@ -52,7 +46,7 @@ while not isNextDisabeled: try: - links_config = config['BMBF'] + links_config = config['example'] projects_loading_phase = WebDriverWait(driver,10).until(EC.presence_of_element_located(( By.XPATH, links_config['loading-project-data'] @@ -65,7 +59,7 @@ while not isNextDisabeled: #saving data into json file: df_links = pd.DataFrame({'project_link':links}) - df_links.to_json("project_links_BMBF2.json", orient='records') + df_links.to_json("project_links_example.json", orient='records') try: next_btn = WebDriverWait(driver, 10).until(EC.presence_of_element_located( diff --git a/README.md b/README.md new file mode 100644 index 0000000..078eec2 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +This frame work is designed to retrieve data from different websites with different structure. +currently: +level #1 of abstraction is done by implementing a config file which stores all the xpath of different fields of +the 3 provided websitel inks +level #2 of abstraction is done by implementing a test conditional based on the website's type (js-based or not) + + + + +############################################################################################################################ + +# step 1 +1. open projectlinks directory +2. edit the links_config.ini +3. open links_extractor.py -> url = config['example']['start-url'] (and other relevent fields) +4. once you entered the configured data, links_extractor file will extract the project links by handeling pagination and saves them in project_links_ProjectName.json + +# step 2 +1. to determine wheather we need scrapy or delenium to scrape data from project links, +I passed the first link stored in project_links_ProjectName.json to selenium_or_scrapy.py +2. this file goes through html markup and searches for