Last active
June 4, 2018 13:01
-
-
Save wwex/6a01be70a643753960073b30183c46e6 to your computer and use it in GitHub Desktop.
[PyMemos - WEB Scratching] #python #memo #web #requests
This file contains hidden or 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
import bs4 | |
res = requests.get('https://www.amazon.com/Automate-Boring-Stuff-Python-Programming/dp/1593275994') | |
res = requests.get('https://www.google.com') | |
res.raise_for_status() | |
soup = bs4.BeautifulSoup(res.text, 'html.parser') | |
elems = soup.select('#gbw > div > div > div.gb_oe.gb_R.gb_Lg.gb_Bg > div:nth-child(2) > a') | |
# print(elems[0].text.strip()) | |
print(elems) |
This file contains hidden or 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 | |
# chromepath = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' | |
# browser = webdriver.Chrome(chromepath) | |
browser = webdriver.Firefox() | |
browser.get('https://automatetheboringstuff.com/') | |
elem = browser.find_element_by_css_selector('.main > div:nth-child(1) > h1:nth-child(1)') | |
print(elem.text) | |
# elem.click() #simulate clicking on lement | |
# elems = browser.find_elements_by_css_selector('p') | |
# searchElem = browser.find_element_by_css_selector('.search-field') | |
# searchElem.send_keys('zophie') | |
# searchElem.submit() | |
# browser.back() | |
# browser.forward() | |
# browser.refresh() | |
# browser.quit() |
This file contains hidden or 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
import requests | |
res = requests.get('https://automatetheboringstuff.com/files/rj.txt') | |
# badres = requests.get('https://automatetheboringstuff.com/files/jkhbvwabf') | |
# print(res.status_code) #200=OK | |
# print(res.text[:500]) | |
# badres.raise_for_status() | |
playFile = open('RomeAndJuliet.txt', 'wb') | |
for chunk in res.iter_content(100000): | |
playFile.write(chunk) | |
playFile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment