Last active
July 4, 2023 14:45
-
-
Save makesomelayouts/7374f0b4845e857964f1df4ea083381f to your computer and use it in GitHub Desktop.
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 | |
| from fake_useragent import UserAgent | |
| response = requests.get('https://httpbin.org/get', headers={'user-agent': UserAgent().random}) | |
| print(response.status_code) | |
| print(f'response.content={response.content}\n') | |
| print(f'response.headers={response.headers}\n') | |
| print(f'response.text={response.text}\n') | |
| print(f'response.json()={response.json()}\n') | |
| # download video: | |
| # with open('1.webm', 'wb') as f: | |
| # for chunk in response.iter_content(chunk_size=1024 * 100): | |
| # f.write(chunk) | |
| from bs4 import BeautifulSoup | |
| soup = BeautifulSoup(response.content, 'lxml') | |
| # h1 = soup.h1 | |
| # print(h1.attrs['id']) | |
| # print(h1['id']) | |
| # print(h1.get('id')) # + | |
| # print(h1.text(strip=True, separator=' ')) | |
| # find() # find_all('a', class_='p-2') | |
| print(soup.a) | |
| print(soup.find('nav').find_all('a')) # + | |
| print(soup.select_one('nav').select('a')) | |
| # <span data-name>The Sad Onion</span> == | |
| # find('span', {'data-name' : True}) | |
| # import soupsieve as sv | |
| # links = sv.select('nav span', soup) | |
| # links = sv.select('nav > span', soup) | |
| # links = sv.select('nav a::is(.test1, .test2)', soup) | |
| # links = sv.select('nav a::not(.test1, .test2)', soup) | |
| # select('table.table tbody tr td:last-child') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment