Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #open a jira isse in the browser
- import webbrowser
- import sys
- import requests
- import pyperclip
- #get the issue number from the clipboard or in input
- if len(sys.argv) == 2 :
- issue = sys.argv[1]
- else :
- issue = pyperclip.paste() #get the content of the clipboard
- sURL = r'https://jira.boc-group.com/browse/' + issue
- webbrowser.open_new(sURL)
- ########################
- # get the page we want do download
- res = requests.get(sURL)
- res.raise_for_status() #exception if the status of the answer from the web is not OK
- print(res.status_code) #verify status of the answer to the request
- #contet of the page
- #print(res.text)
- #to parse the HTML in a page retrieved with the request module
- #allows to retrieve a specific info from a website
- soup = bs4.beautifulsoup4(res.text, 'html.parser')
- #the lement is the one we can find in the browser with select element and after copy css path
- elems = soup.select(sElement)
- #get the text of the element and string all the white spaces
- elems[0].text.strip()
- #######################
- #Selenium start a browser that can be controlled by python, not just getting a page and parsing it
- #but actually executing actions with the elements we retrn
- #######################
- from selenium import webdriver
- browser = webdriver.Firefox() #start firefox
- browser.get(sURL)
- elem = browser.find_element_by_css_selector(sElement) #one of the many getters for HTML elements
- elem.click()
- searchElem = browser.find_element_by_css_selector(sElement)
- searchElem.send_keys('fabio')
- searchElem.submit() #not necessary to actually find the button and click on okay. Selenium understands which is the form and automatically does it
- browser.back()
- browser.forward()
- browser.refresh()
- browser.quit()
- #to simply read an HTML element
- searchElem = browser.find_element_by_css_selector(sElement)
- searchElem.text
- searchElem = browser.find_element_by_css_selector('html') #get the whole page
Advertisement
Add Comment
Please, Sign In to add comment