This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium.webdriver.support.wait import WebDriverWait | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support import expected_conditions as EC | |
search_box = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, 'input[id="orb-search-q"]'))) | |
#search_box = driver.find_element_by_css_selector('input[id="orb-search-q"]') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium.webdriver.chrome.options import Options | |
headless_options = Options() | |
headless_options.add_argument('--headless') | |
driver = webdriver.Chrome(options=headless_options) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
top_titles = driver.find_elements_by_css_selector('div[class="css-14rwwjy-Promo ett16tt11"]') | |
with open('Coronavirus_headlines.txt', 'w') as cor_virus: | |
for title in top_titles: | |
headline = title.find_element_by_css_selector('p[class="css-1aofmbn-PromoHeadline ett16tt4"]').text | |
cor_virus.write('\n') | |
cor_virus.write(headline) | |
print(headline) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
search_box = driver.find_element_by_css_selector('input[id="orb-search-q"]') | |
ActionChains(driver).move_to_element(search_box).click()\ | |
.send_keys('Global coronavirus updates').key_down(Keys.ENTER).perform() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
driver = webdriver.Chrome() | |
driver.get('https://www.bbc.co.uk/news') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Magic methods through short code snippets | |
class Restaurants(object): | |
def __init__(self, wk1): | |
self._wk1 = wk1 | |
def __setattr__(self, key, value): | |
if not isinstance(value, list): | |
raise TypeError('please enter weekly takings a list') | |
for val in value: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
total = wk1_city_1 + wk1_city_2 | |
print(total) | |
total = wk1_city_1.__add__(wk1_city_2) | |
print(total) | |
# Output | |
# [30, 60, 90, 120, 150] | |
# [30, 60, 90, 120, 150] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(dir(dict)) | |
print(dir(list)) | |
# Output | |
['__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values'] | |
['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Restaurants(object): | |
def __init__(self, wk1): | |
self._wk1 = wk1 | |
def __repr__(self): | |
return 'Restaurants({})'.format(self._wk1) | |
wk1_city_1 = Restaurants([10, 20, 30, 40, 50]) | |
print(wk1_city_1) |