Programming 2 Lectures
Programming 2 Lectures
Meraryslan Meraliyev
October 9, 2024
1
Table of Contents
2
Introduction to Data Collection
Introduction to Data Collection
3
Working with Files and Directories
Overview of File Operations in Python
4
Reading a File in Python
5
Writing to a File
6
Appending Data to a File
7
Short Task: File Operations
8
Working with Directories in Python
9
Short Task: Directory Operations
10
APIs and Data Retrieval
What are APIs?
11
Making API Requests with Python
12
Short Task: Working with APIs
13
Handling API Authentication
14
Working with API Pagination
3 while url :
4 response = requests . get ( url )
5 data = response . json ()
6
16
Data Collection from Databases
Introduction to SQL Databases
17
Basic SQL Commands
18
Querying a Database with SQLite
20
Web Scraping
Introduction to Web Scraping
21
Introduction to BeautifulSoup
22
Basic Scraping with BeautifulSoup
23
Navigating HTML Structure with BeautifulSoup
24
Searching for Elements by Attribute
25
Extracting Data from Tables
26
Handling Forms with BeautifulSoup
28
Handling Pagination in Scraping
30
Introduction to Selenium
31
Setting Up Selenium
32
Interacting with Web Elements using Selenium
33
Handling Dynamic Content with Selenium
34
Running Selenium in Headless Mode
3 chrome_options = Options ()
4 chrome_options . add_argument ( " -- headless " )
5
36
Conclusion on Web Scraping
37
Real-time Data Collection
Introduction to WebSockets
38
Receiving Real-time Data via WebSockets
39
Short Task: Real-time Data Collection
40
Automation and Scheduling
Automating Tasks with Python
4 def collect_data () :
5 print ( " Collecting data ... " )
6
9 while True :
10 schedule . run_pending ()
11 time . sleep (1)
12
41
Short Task: Scheduling Tasks
42
Conclusion and Best Practices
Conclusion: Best Practices for Data Collection
43
Next Steps in Data Collection
44