Advertisement
Guest User

Untitled

a guest
Jan 15th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. # -*- coding: cp1252 -*-
  2. from bs4 import BeautifulSoup
  3. import html5lib
  4. import urllib
  5. from selenium import webdriver
  6. from selenium.webdriver.common.by import By
  7. import string
  8. import requests
  9. from requests.auth import HTTPBasicAuth
  10.  
  11. danskAlf = list(string.ascii_uppercase)
  12. #danskAlf.append("Æ")
  13. #danskAlf.append("Ø")
  14. #danskAlf.append("Å")
  15.  
  16.  
  17. driver = webdriver.Firefox()
  18. driver.get("http://xnet.dkma.dk/indlaegsseddel/leaflets/leaflets.faces")
  19.  
  20. for i in range(2):
  21.    
  22.     search = driver.find_element_by_partial_link_text(danskAlf[i])
  23.  
  24.     search.click()
  25.  
  26.  
  27.     soup = BeautifulSoup(driver.page_source, 'html.parser')
  28.  
  29.     res = []
  30.     for i in soup.findAll("tr", {"class" : "odd"}):
  31.         respDict = {}
  32.         respDict["name"] = i.text.splitlines()[0]
  33.         respDict["producer"] = i.text.splitlines()[1]
  34.         respDict["form"] = i.text.splitlines()[2]
  35.         respDict["dose"] = i.text.splitlines()[3]
  36.         res.append(respDict)
  37.  
  38.     for i in soup.findAll("tr", {"class" : "even"}):
  39.         respDict = {}
  40.         respDict["name"] = i.text.splitlines()[0]
  41.         respDict["producer"] = i.text.splitlines()[1]
  42.         respDict["form"] = i.text.splitlines()[2]
  43.         respDict["dose"] = i.text.splitlines()[3]
  44.         res.append(respDict)
  45.  
  46.     sendResp(res, danskAlf[i])
  47.  
  48.  
  49. def sendResp(resp, letter):
  50.     url = "https://qa-engine.scaut.dk/integration/pharmaceutical"
  51.     user = "scraper"
  52.     password = "1234"
  53.    
  54.     payload = {}
  55.     payload["Medicines with start letter \""+letter+"\""] = resp
  56.  
  57.    
  58.  
  59.     r = requests.post(url, json=payload, auth=HTTPBasicAuth(user, password))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement