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 bs4 import BeautifulSoup | |
import requests | |
hdr = {'User-Agent': 'your user-agent info here'} | |
# find YOUR user-agent HERE: https://www.whatismybrowser.com/detect/what-is-my-user-agent/ | |
url = 'https://www.some_domain.com/some_dir' | |
page = requests.get(url, headers=hdr) | |
soup = BeautifulSoup(page.text, 'html.parser') | |
''' |
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
<?php | |
// allow error reporting | |
ini_set('display_errors', 1); | |
ini_set('display_startup_errors', 1); | |
error_reporting(E_ALL); | |
?> | |
<?php | |
try { | |
// connect to database |
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
# lots of code missing here! Just showing db commands | |
# my model - table named socks - the model matches the real table in your db | |
class Sock(db.Model): | |
__tablename__ = 'socks' | |
id = db.Column(db.Integer, primary_key=True) | |
name = db.Column(db.String) | |
style = db.Column(db.String) | |
color = db.Column(db.String) | |
quantity = db.Column(db.Integer) |
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
""" | |
Flask example using Requests library syntax to build | |
a Wikipedia API query - no templates, just raw HTML | |
written straight into the browser. | |
This code was partly written by ChatGPT. | |
""" | |
from flask import Flask, jsonify, request, redirect, url_for | |
import random, requests |
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
"""Demonstrates extraction of data from a Wikipedia API request""" | |
import requests | |
API_URL = 'https://en.wikipedia.org/w/api.php?action=query&origin=*&format=json&generator=search&gsrnamespace=0&gsrlimit=10&gsrsearch={}' | |
search_term = "David_Bowie" | |
data = requests.get(API_URL.format(search_term)).json() |
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
""" | |
Find the main image on a Wikipedia page and download it. | |
Using a list of Wikipedia URLs, download the main image from each page in the list. | |
Name the downloaded file to match the page URL. | |
""" | |
import requests, os | |
# set the folder name where images will be stored | |
my_folder = 'wiki_images' |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title> Detect 404 </title> | |
</head> | |
<body> | |
<p>Hello.</p> |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>{{ pres["President"] }}</title> | |
<link rel="stylesheet" href="{{ url_for('static', filename='main.css') }}"> | |
</head> | |
<body> |
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 flask import Flask | |
app = Flask(__name__) | |
import csv | |
def convert_to_dict(filename): | |
datafile = open(filename, newline='') | |
my_reader = csv.DictReader(datafile) | |
list_of_dicts = list(my_reader) | |
datafile.close() |
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 https://frontendmasters.github.io/bootcamp/ajax - more info there | |
const BREEDS_URL = "https://dog.ceo/api/breeds/image/random"; | |
const promise = fetch(BREEDS_URL); | |
promise | |
.then(function(response) { | |
const processingPromise = response.json(); | |
return processingPromise; |
NewerOlder