You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

766 lines
36 KiB

  1. import os
  2. import yaml
  3. import json
  4. import urllib.request, urllib.error, urllib.parse
  5. from lxml import etree
  6. import lxml.html
  7. import lxml.html.soupparser
  8. from lxml import html
  9. import requests
  10. from trafilatura import extract
  11. from pdfminer.high_level import extract_pages
  12. from pdfminer.layout import LTTextContainer
  13. class fdb_spider(object):
  14. def __init__(self, config_file):
  15. with open(config_file, "r") as stream:
  16. try:
  17. self.config = yaml.safe_load(stream)
  18. except yaml.YAMLError as exc:
  19. print(exc)
  20. # input list of funding databases in form of yaml file ['foerderinfo.bund.de', 'ausschreibungen.giz.de', .. , 'usw']
  21. def download_entry_list_pages_of_funding_databases(self, list_of_fdbs):
  22. # download only html pages of the funding databases specified in input
  23. for fdb in list_of_fdbs:
  24. for key in self.config:
  25. if key in list_of_fdbs:
  26. try:
  27. entry_list = self.config.get(key).get("entry-list")
  28. except Exception as e:
  29. print(
  30. "There is a problem with the configuration variable entryList in the config.yaml - the original error message is:",
  31. e,
  32. )
  33. try:
  34. entry_list_link1 = entry_list.get("link1")
  35. except Exception as e:
  36. print(
  37. "No link1 defined in config.yaml - the original error message is:",
  38. e,
  39. )
  40. try:
  41. entry_list_link2 = entry_list.get("link2")
  42. except Exception as e:
  43. print(
  44. "No link2 defined in config.yaml - the original error message is:",
  45. e,
  46. )
  47. try:
  48. entry_iteration_var_list = eval(entry_list.get("iteration-var-list"))
  49. except Exception as e:
  50. print(
  51. "No iteration-var-list defined in config.yaml - the original error message is:",
  52. e,
  53. )
  54. for i in entry_iteration_var_list:
  55. # download the html page of the List of entrys
  56. response = urllib.request.urlopen(entry_list_link1 + str(i) + entry_list_link2)
  57. # web_content = response.read().decode("UTF-8")
  58. try:
  59. web_content = response.read().decode("UTF-8")
  60. except Exception as e:
  61. try:
  62. web_content = response.read().decode("latin-1")
  63. print(
  64. "decoding the respone in utf8 did not work, try to decode latin1 now - the original error message is:",
  65. e,
  66. )
  67. except Exception as ex:
  68. print(ex)
  69. # save interim results to files
  70. if (len(web_content)) < 10:
  71. print('getting the html page through urllib did not work, trying with requests librarys function get')
  72. try:
  73. res = requests.get(entry_list_link1 + str(i) + entry_list_link2)
  74. web_content = res.text
  75. except Exception as e:
  76. print('also requests library did not work, original error is:', e)
  77. # print(web_content)
  78. f = open("spiders/pages/" + key + str(i) + "entryList.html", "w+")
  79. f.write(web_content)
  80. f.close
  81. def find_config_parameter(self, list_of_fdbs):
  82. for fdb in list_of_fdbs:
  83. try:
  84. iteration_var_list = eval(self.config.get(fdb).get("entry-list").get("iteration-var-list"))
  85. except Exception as e:
  86. print(
  87. "There is a problem with the configuration variable entryList iteration var list in the config.yaml",
  88. e,
  89. )
  90. fdb_conf = self.config.get(fdb)
  91. fdb_domain = fdb_conf.get("domain")
  92. fdb_conf_entry_list = fdb_conf.get("entry-list")
  93. fdb_conf_entry_list_parent = fdb_conf_entry_list.get("parent")
  94. fdb_conf_entry_list_child_name = fdb_conf_entry_list.get("child-name")
  95. fdb_conf_entry_list_child_link = fdb_conf_entry_list.get("child-link")
  96. fdb_conf_entry_list_child_info = fdb_conf_entry_list.get("child-info")
  97. fdb_conf_entry_list_child_period = fdb_conf_entry_list.get("child-period")
  98. for i in iteration_var_list:
  99. print(i)
  100. try:
  101. # use soupparser to handle broken html
  102. tree = lxml.html.soupparser.parse(
  103. "spiders/pages/" + fdb + str(i) + "entryList.html"
  104. )
  105. except Exception as e:
  106. tree = html.parse("spiders/pages/" + fdb + str(i) + "entryList.html")
  107. print(
  108. "parsing the xml files did not work with the soupparser. Broken html will not be fixed as it could have been",
  109. e,
  110. )
  111. try:
  112. print('this is the n looped elements of the parent specified in config.yaml:')
  113. #print('entrylistparent', fdb_conf_entry_list_parent)
  114. #print(tree.xpath("//html//body//div//main//div//div[@class='row']//section[@class='l-search-result-list']"))
  115. #print(etree.tostring(tree.xpath(fdb_conf_entry_list_parent)).decode())
  116. for n in range(len(tree.xpath(fdb_conf_entry_list_parent))):
  117. print('-----------------------------------------------------------------------------------------------------------------------------------------')
  118. print(etree.tostring(tree.xpath(fdb_conf_entry_list_parent)[n]).decode())
  119. print('this is the name children:')
  120. name_element = tree.xpath(fdb_conf_entry_list_parent + fdb_conf_entry_list_child_name)
  121. print(name_element)
  122. #for name in name_element:
  123. # print(name)
  124. print(len(name_element))
  125. print('this is the link children:')
  126. link_element = tree.xpath(fdb_conf_entry_list_parent + fdb_conf_entry_list_child_link)
  127. print(link_element)
  128. #for link in link_element:
  129. # print(link)
  130. print(len(link_element))
  131. print('this is the info children:')
  132. info_element = tree.xpath(fdb_conf_entry_list_parent + fdb_conf_entry_list_child_info)
  133. print(info_element)
  134. print(len(info_element))
  135. print('this is the period children:')
  136. period_element = tree.xpath(fdb_conf_entry_list_parent + fdb_conf_entry_list_child_period)
  137. print(period_element)
  138. print(len(period_element))
  139. except Exception as e:
  140. print(
  141. "parsing the html did not work.",
  142. e,
  143. )
  144. def parse_entry_list_data2dictionary(self, list_of_fdbs):
  145. for fdb in list_of_fdbs:
  146. try:
  147. iteration_var_list = eval(self.config.get(fdb).get("entry-list").get("iteration-var-list"))
  148. except Exception as e:
  149. print(
  150. "There is a problem with the configuration variable entryList iteration var list in the config.yaml - the original error message is:",
  151. e,
  152. )
  153. for i in iteration_var_list:
  154. print(i)
  155. try:
  156. # use soupparser to handle broken html
  157. tree = lxml.html.soupparser.parse(
  158. "spiders/pages/" + fdb + str(i) + "entryList.html"
  159. )
  160. except Exception as e:
  161. tree = html.parse("spiders/pages/" + fdb + str(i) + "entryList.html")
  162. print(
  163. "parsing the xml files did not work with the soupparser. Broken html will not be fixed as it could have been, thanks to efficient particular html languages. The original error message is:",
  164. e,
  165. )
  166. try:
  167. #print('this is the n looped elements of the parent specified in config.yaml:')
  168. #for e in tree.iter():
  169. # print(e.tag)
  170. #
  171. #for e in tree.xpath("//html//body//div//main//div//div[@class='row']//section[@class='l-search-result-list']//div//div[@class='c-search-result__text-wrapper']//span[@class='c-search-result__title'][text()]"):
  172. #for e in tree.xpath("//html//body//div//main//div//div[@class='row']//section[@class='l-search-result-list']//div//div[@class='c-search-result__text-wrapper']//span[@class='c-search-result__title']"):
  173. # print(etree.tostring(e).decode())
  174. dictionary_entry_list = {}
  175. fdb_conf = self.config.get(fdb)
  176. fdb_domain = fdb_conf.get("domain")
  177. fdb_conf_entry_list = fdb_conf.get("entry-list")
  178. fdb_conf_entry_list_parent = fdb_conf_entry_list.get("parent")
  179. fdb_conf_entry_list_child_name = fdb_conf_entry_list.get("child-name")
  180. fdb_conf_entry_list_child_link = fdb_conf_entry_list.get("child-link")
  181. fdb_conf_entry_list_child_info = fdb_conf_entry_list.get("child-info")
  182. fdb_conf_entry_list_child_period = fdb_conf_entry_list.get("child-period")
  183. #print('blabliblub')
  184. #print('len', len(tree.xpath(fdb_conf_entry_list_parent)))
  185. for n in range(len(tree.xpath(fdb_conf_entry_list_parent))):
  186. try:
  187. name = tree.xpath(
  188. fdb_conf_entry_list_parent
  189. + "["
  190. + str(n+1)
  191. + "]"
  192. + fdb_conf_entry_list_child_name
  193. )[0]
  194. except Exception as e:
  195. print("name could not be parsed", e)
  196. name = 'NONE'
  197. try:
  198. info = tree.xpath(
  199. fdb_conf_entry_list_parent
  200. + "["
  201. + str(n+1)
  202. + "]"
  203. + fdb_conf_entry_list_child_info
  204. )[0]
  205. except Exception as e:
  206. print("info could not be parsed", e, info)
  207. info = 'NONE'
  208. try:
  209. period = tree.xpath(
  210. fdb_conf_entry_list_parent
  211. + "["
  212. + str(n+1)
  213. + "]"
  214. + fdb_conf_entry_list_child_period
  215. )[0]
  216. #print('period', period)
  217. except Exception as e:
  218. print("period could not be parsed", e, period)
  219. period = 'NONE'
  220. try:
  221. link = tree.xpath(
  222. fdb_conf_entry_list_parent
  223. + "["
  224. + str(n+1)
  225. + "]"
  226. + fdb_conf_entry_list_child_link
  227. )[0]
  228. if 'javascript:' in link:
  229. #from selenium import webdriver
  230. print('link is javascript element, not url to parse')
  231. #url = 'https://example.com'
  232. #driver = webdriver.Chrome()
  233. #driver.get(url)
  234. #links = [link.get_attribute('href') for link in driver.find_elements_by_tag_name('a')]
  235. #print('link', link)
  236. except Exception as e:
  237. print("link could not be parsed", e, link)
  238. link = 'NONE'
  239. if len(name) > 0 and name != 'NONE':
  240. dictionary_entry_list[n] = {}
  241. dictionary_entry_list[n]["name"] = name
  242. dictionary_entry_list[n]["info"] = info
  243. dictionary_entry_list[n]["period"] = period
  244. if fdb_domain in link:
  245. dictionary_entry_list[n]["link"] = link
  246. if fdb_domain not in link and 'http:' in link:
  247. dictionary_entry_list[n]["link"] = link
  248. if fdb_domain not in link and 'www.' in link:
  249. dictionary_entry_list[n]["link"] = link
  250. if fdb_domain not in link and 'https:' in link:
  251. dictionary_entry_list[n]["link"] = link
  252. if 'javascript:' in link:
  253. dictionary_entry_list[n]["link"] = link
  254. if fdb_domain not in link and ('http' or 'https' or 'www.') not in link:
  255. if link[-1] == '/':
  256. dictionary_entry_list[n]["link"] = fdb_domain + link
  257. else:
  258. dictionary_entry_list[n]["link"] = fdb_domain + '/' + link
  259. except Exception as e:
  260. print(
  261. "parsing the html did not work. Possibly you first have to run download_link_list_pages_of_funding_databases(). The original error message is:",
  262. e,
  263. )
  264. # save interim results to files
  265. f = open("spiders/output/" + fdb + str(i) + "entryList.txt", "w+")
  266. f.write(str(dictionary_entry_list))
  267. f.close
  268. def download_entry_data_htmls(self, list_of_fdbs):
  269. from selenium import webdriver
  270. from selenium.webdriver.chrome.service import Service
  271. from pyvirtualdisplay import Display
  272. display = Display(visible=0, size=(800, 800))
  273. display.start()
  274. #outputdir = '.'
  275. #service_log_path = "{}/chromedriver.log".format(outputdir)
  276. #service_args = ['--verbose']
  277. #driver = webdriver.Chrome('/usr/bin/chromium')
  278. options = webdriver.ChromeOptions()
  279. options.add_argument('headless')
  280. options.add_argument("--remote-debugging-port=9222")
  281. options.add_argument('--no-sandbox')
  282. options.add_argument('--disable-dev-shm-usage')
  283. service = Service(executable_path='/usr/bin/chromedriver')
  284. driver = webdriver.Chrome(options=options, service=service)
  285. #driver = webdriver.Chrome()
  286. for fdb in list_of_fdbs:
  287. try:
  288. iteration_var_list = eval(self.config.get(fdb).get("entry-list").get("iteration-var-list"))
  289. except Exception as e:
  290. print(
  291. "There is a problem with the configuration variable entryList iteration var list in the config.yaml - the original error message is:",
  292. e,
  293. )
  294. print('starting to download the entry html pages..')
  295. for i in iteration_var_list:
  296. print(i)
  297. f = open("spiders/output/" + fdb + str(i) + "entryList.txt")
  298. text = f.read()
  299. dictionary_entry_list = eval(text)
  300. fdb_conf = self.config.get(fdb)
  301. fdb_domain = fdb_conf.get("domain")
  302. fdb_conf_entry_list = fdb_conf.get("entry-list")
  303. fdb_conf_entry_list_parent = fdb_conf_entry_list.get("parent")
  304. fdb_conf_entry_list_child_name = fdb_conf_entry_list.get("child-name")
  305. try:
  306. fdb_conf_entry_list_javascript_link = fdb_conf_entry_list.get("javascript-link")
  307. except Exception as e:
  308. print('the javascript link in the config is missing, original error message is:', e)
  309. fdb_conf_entry_list_link1 = fdb_conf_entry_list.get("link1")
  310. fdb_conf_entry_list_link2 = fdb_conf_entry_list.get("link2")
  311. driver.get(fdb_conf_entry_list_link1 + str(i) + fdb_conf_entry_list_link2)
  312. for entry_id in dictionary_entry_list:
  313. entry_link = dictionary_entry_list[entry_id]["link"]
  314. web_content = 'NONE'
  315. # download the html page of the entry
  316. if 'javascript' in entry_link:
  317. element = driver.find_element(
  318. "xpath",
  319. fdb_conf_entry_list_parent
  320. + "["
  321. + str(entry_id+1)
  322. + "]"
  323. + fdb_conf_entry_list_javascript_link
  324. )
  325. # to time.sleep was suggested for errors
  326. #import time
  327. #time.sleep(1)
  328. element.click()
  329. window_after = driver.window_handles[1]
  330. driver.switch_to.window(window_after)
  331. #element = driver.find_element("xpath", "//html")
  332. #web_content = element.text
  333. #entry_domain = driver.getCurrentUrl()
  334. entry_domain = driver.current_url
  335. dictionary_entry_list[entry_id]["domain"] = entry_domain
  336. web_content = driver.page_source
  337. file_name = "spiders/pages/" + fdb + str(i) + "/" + str(entry_id) + ".html"
  338. os.makedirs(os.path.dirname(file_name), exist_ok=True)
  339. f = open(file_name, "w+")
  340. f.write(web_content)
  341. f.close
  342. window_before = driver.window_handles[0]
  343. driver.switch_to.window(window_before)
  344. if ('http' or 'www') in entry_link and 'javascript' not in entry_link and '.pdf' not in entry_link:
  345. try:
  346. # defining cookie to not end up in endless loop because of cookie banners pointing to redirects
  347. url = entry_link
  348. req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0', 'Cookie':'myCookie=lovely'})
  349. response = urllib.request.urlopen(req)
  350. except Exception as e:
  351. try:
  352. response = urllib.request.urlopen(entry_link.encode('ascii', errors='xmlcharrefreplace').decode('ascii'))
  353. print(
  354. "opening the link did not work, try to encode to ascii replacing xmlcharrefs now and reopen - the original error message is:",
  355. e,
  356. )
  357. except Exception as ex:
  358. print(entry_link, entry_link.encode('ascii', errors='xmlcharrefreplace').decode('ascii'), ex )
  359. try:
  360. web_content = response.read().decode("UTF-8")
  361. except Exception as e:
  362. try:
  363. web_content = response.read().decode("latin-1")
  364. print(
  365. "decoding the respone in utf8 did not work, try to decode latin1 now - the original error message is:",
  366. e,
  367. )
  368. except Exception as ex:
  369. print(ex)
  370. # save interim results to files
  371. if '.pdf' in entry_link:
  372. file_name = "spiders/pages/" + fdb + str(i) + "/" + str(entry_id) + ".html"
  373. response = requests.get(entry_link)
  374. os.makedirs(os.path.dirname(file_name), exist_ok=True)
  375. f = open(file_name, "bw")
  376. f.write(response.content)
  377. f.close
  378. else:
  379. file_name = "spiders/pages/" + fdb + str(i) + "/" + str(entry_id) + ".html"
  380. if web_content == 'NONE':
  381. print('other downloading approaches did not work, trying requests')
  382. try:
  383. from requests_html import HTMLSession
  384. session = HTMLSession()
  385. r = session.get(entry_link)
  386. r.html.render()
  387. web_content = r.text
  388. except Exception as e:
  389. print('requests_html HTMLSession did not work')
  390. os.makedirs(os.path.dirname(file_name), exist_ok=True)
  391. f = open(file_name, "w+")
  392. f.write(web_content)
  393. f.close
  394. # save the entry_domain, implemented first for further downloads in javascript links
  395. f = open("spiders/output/" + fdb + str(i) + "entryList.txt", "w+")
  396. f.write(str(dictionary_entry_list))
  397. f.close
  398. def parse_entry_data2dictionary(self, list_of_fdbs):
  399. for fdb in list_of_fdbs:
  400. try:
  401. fdb_config = self.config.get(fdb)
  402. print('oi oi',fdb_config)
  403. fdb_config_entrylist = fdb_config.get("entry-list")
  404. iteration_var_list = eval(fdb_config_entrylist.get("iteration-var-list"))
  405. except Exception as e:
  406. print(
  407. "There is a problem with the configuration variable entryList iteration var list in the config.yaml - the original error message is:",
  408. e,
  409. )
  410. for i in iteration_var_list:
  411. print("started to parse data of entry of " + fdb + " ..")
  412. f = open("spiders/output/" + fdb + str(i) + "entryList.txt")
  413. text = f.read()
  414. dictionary_entry_list = eval(text)
  415. fdb_conf = self.config.get(fdb)
  416. fdb_domain = fdb_conf.get("domain")
  417. fdb_conf_entry = fdb_conf.get("entry")
  418. #print('balubaluba', fdb_conf_entry)
  419. fdb_conf_entry_general = fdb_conf_entry.get("general")
  420. #print(fdb_conf_entry_general)
  421. for entry_id in dictionary_entry_list:
  422. print(
  423. "started to parse data of entry with name "
  424. + dictionary_entry_list[entry_id]["name"]
  425. + " .."
  426. )
  427. file_name = "spiders/pages/" + fdb + str(i) + "/" + str(entry_id) + ".html"
  428. try:
  429. tree = lxml.html.soupparser.parse(file_name)
  430. except Exception as e:
  431. tree = html.parse(file_name)
  432. print(
  433. "parsing the xml files did not work with the soupparser. Broken html will not be fixed as it could have been, thanks to efficient particular html languages. The original error message is:",
  434. e,
  435. )
  436. if fdb_conf_entry_general["uniform"] == 'TRUE':
  437. fdb_conf_entry_unitrue = fdb_conf_entry.get("unitrue")
  438. for key in fdb_conf_entry_unitrue:
  439. fdb_conf_entry_unitrue_child = fdb_conf_entry_unitrue.get(key)
  440. child = tree.xpath(
  441. fdb_conf_entry_unitrue_child
  442. )[0]
  443. print("oi", child)
  444. if '.pdf' in child:
  445. print('child in entry data is pdf, downloading it..')
  446. file_name = "spiders/pages/" + fdb + str(i) + "/" + str(entry_id) + ".pdf"
  447. entry_link = dictionary_entry_list[entry_id]["link"]
  448. if 'http' not in child:
  449. if 'javascript' or 'js' not in entry_link and 'http' in entry_link:
  450. try:
  451. response = requests.get(entry_link + child)
  452. except Exception as e:
  453. print(entry_link + child + ' seems not a valid pdf link to download, orginal error message is:', e)
  454. if 'javascript' or 'js' in entry_link:
  455. entry_domain = dictionary_entry_list[entry_id]["domain"]
  456. if child[0] == '.' and child[1] == '/':
  457. if entry_domain[-1] == '/':
  458. pdf_link = entry_domain[:-1] + child[1:]
  459. if entry_domain[-1] != '/':
  460. for n in range(len(entry_domain)):
  461. if entry_domain[-1] != '/':
  462. entry_domain = entry_domain[:-1]
  463. else:
  464. break
  465. pdf_link = entry_domain + child[1:]
  466. if child[0] == '/':
  467. if entry_domain[-1] == '/':
  468. pdf_link = entry_domain[:-1] + child
  469. if entry_domain[-1] != '/':
  470. pdf_link = entry_domain + child
  471. print('pdf_link', pdf_link)
  472. try:
  473. response = requests.get(pdf_link)
  474. except Exception as e:
  475. print(pdf_link + ' seems not a valid pdf link to download, orginal error message is:', e)
  476. #response = requests.get(child)
  477. os.makedirs(os.path.dirname(file_name), exist_ok=True)
  478. f = open(file_name, "bw")
  479. f.write(response.content)
  480. f.close
  481. print('parsing a pdf', pdf_link, entry_id)
  482. try:
  483. generaltext = ''
  484. for page_layout in extract_pages(file_name):
  485. for element in page_layout:
  486. if isinstance(element, LTTextContainer):
  487. generaltext += element.get_text()
  488. except Exception as e:
  489. generaltext = 'NONE'
  490. print('parsing pdf did not work, the original error is:', e )
  491. dictionary_entry_list[entry_id][key] = generaltext
  492. if len(child) > 0 and '.pdf' not in child:
  493. dictionary_entry_list[entry_id][key] = child[
  494. 0
  495. ]
  496. else:
  497. fdb_conf_entry_unifalse = fdb_conf_entry.get("unifalse")
  498. fdb_conf_entry_unifalse_wordlist = fdb_conf_entry_unifalse.get("wordlist")
  499. if '.pdf' in dictionary_entry_list[entry_id]["link"]:
  500. print('parsing a pdf', dictionary_entry_list[entry_id]["link"], entry_id)
  501. try:
  502. generaltext = ''
  503. for page_layout in extract_pages(file_name):
  504. for element in page_layout:
  505. if isinstance(element, LTTextContainer):
  506. generaltext += element.get_text()
  507. except Exception as e:
  508. generaltext = 'NONE'
  509. print('parsing pdf did not work, the original error is:', e )
  510. else:
  511. p_text = tree.xpath(
  512. "//p//text()"
  513. )
  514. div_text = tree.xpath(
  515. "//div//text()"
  516. )
  517. #print("oi", text)
  518. generaltext = ''
  519. for n in range(len(p_text)):
  520. if len(p_text[n]) > 0:
  521. generaltext += p_text[n] + ' '
  522. for n in range(len(div_text)):
  523. if len(div_text[n]) > 0 and div_text[n] not in p_text:
  524. generaltext += div_text[n] + ' '
  525. generaltextlist = generaltext.split(' ')
  526. if len(generaltextlist) > 5000:
  527. print('text over 1000 words for entry id', entry_id, ' number of words:', len(generaltextlist))
  528. file_name = "spiders/pages/" + fdb + str(i) + "/" + str(entry_id) + ".html"
  529. try:
  530. with open(file_name , 'r', encoding='utf-8') as file:
  531. html_content = file.read()
  532. except Exception as e:
  533. with open(file_name , 'r', encoding='latin-1') as file:
  534. html_content = file.read()
  535. print('encoding utf8 in opening with trafilatura did not work, trying latin1, original error message is:', e)
  536. generaltext = extract(html_content)
  537. print('generaltext word count was: ', len(generaltextlist), 'but now trafilatura did the job and new wordcount is:', len(generaltext.split(' ')))
  538. if len(generaltextlist) < 2:
  539. print('no text parsed, the wc is', len(generaltextlist))
  540. print('text under 2 words for entry id', entry_id, ' number of words:', len(generaltextlist))
  541. file_name = "spiders/pages/" + fdb + str(i) + "/" + str(entry_id) + ".html"
  542. try:
  543. with open(file_name , 'r', encoding='utf-8') as file:
  544. html_content = file.read()
  545. except Exception as e:
  546. with open(file_name , 'r', encoding='latin-1') as file:
  547. html_content = file.read()
  548. print('encoding utf8 in opening with trafilatura did not work, trying latin1, original error message is:', e)
  549. generaltext = extract(html_content)
  550. try:
  551. if len(generaltext) > 2:
  552. print('generaltext word count was: ', len(generaltextlist), 'but now trafilatura did the job and new wordcount is:', len(generaltext.split(' ')))
  553. except:
  554. print('trafilatura got this out:', generaltext , 'setting generaltext to NONE')
  555. generaltext = 'NONE'
  556. dictionary_entry_list[entry_id]["text"] = generaltext
  557. dictionary_entry_list[entry_id]["text-word-count"] = len(generaltextlist)
  558. f = open("spiders/output/" + fdb + str(i) + "entryList.txt", "w+")
  559. f.write(str(dictionary_entry_list))
  560. f.close