This document details my learnings and assignment work on web scraping using Python. It covers file operations, web scraping techniques using the requests library and BeautifulSoup, and automating data collection from websites. Each concept is explained with detailed steps and code examples.


📁 File Operations

1. Reading Files

# Open a file in read mode
f = open("test.txt", "r")
print(f.read())
f.close()

2. Reading Lines from a File

f = open("test.txt", "r")
all_lines = f.readlines()

for line in all_lines:
    print(line)

f.close()

3. Writing to Files

f = open("test.txt", "w")
f.write("hello")
f.close()

4. Appending to Files

f = open("test.txt", "a")

for i in range(30):
    f.write("\\\\nI love python " + str(i))

f.close()

🌐 Web Scraping with BeautifulSoup

1. Setup

import requests
from bs4 import BeautifulSoup

2. Fetching Web Pages