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.
# Open a file in read mode
f = open("test.txt", "r")
print(f.read())
f.close()
f = open("test.txt", "r")
all_lines = f.readlines()
for line in all_lines:
print(line)
f.close()
f = open("test.txt", "w")
f.write("hello")
f.close()
f = open("test.txt", "a")
for i in range(30):
f.write("\\\\nI love python " + str(i))
f.close()
import requests
from bs4 import BeautifulSoup