From 1b19007a971aeec5067e30b1bd631033f66ca716 Mon Sep 17 00:00:00 2001 From: SARTHAK ASTHANA Date: Wed, 21 Oct 2020 13:18:22 +0530 Subject: [PATCH 1/2] Web Scrapping Folder added --- C++/bubble_sort.cpp | 80 ++++++++++---------- Python/Web Scrapping/BeautifulSoup.py | 104 ++++++++++++++++++++++++++ 2 files changed, 144 insertions(+), 40 deletions(-) create mode 100644 Python/Web Scrapping/BeautifulSoup.py diff --git a/C++/bubble_sort.cpp b/C++/bubble_sort.cpp index 831572c..89d627c 100644 --- a/C++/bubble_sort.cpp +++ b/C++/bubble_sort.cpp @@ -1,41 +1,41 @@ -#include -using namespace std; -void swapping(int &a, int &b) { //swap the content of a and b - int temp; - temp = a; - a = b; - b = temp; -} -void display(int *array, int size) { - for(int i = 0; i array[j+1]) { //when the current item is bigger than next - swapping(array[j], array[j+1]); - swaps = 1; //set swap flag - } - } - if(!swaps) - break; // No swap in this pass, so array is sorted - } -} -int main() { - int n; - cout << "Enter the number of elements: "; - cin >> n; - int arr[n]; //create an array with given number of elements - cout << "Enter elements:" << endl; - for(int i = 0; i> arr[i]; - } - cout << "Array before Sorting: "; - display(arr, n); - bubbleSort(arr, n); - cout << "Array after Sorting: "; - display(arr, n); +#include +using namespace std; +void swapping(int &a, int &b) { //swap the content of a and b + int temp; + temp = a; + a = b; + b = temp; +} +void display(int *array, int size) { + for(int i = 0; i array[j+1]) { //when the current item is bigger than next + swapping(array[j], array[j+1]); + swaps = 1; //set swap flag + } + } + if(!swaps) + break; // No swap in this pass, so array is sorted + } +} +int main() { + int n; + cout << "Enter the number of elements: "; + cin >> n; + int arr[n]; //create an array with given number of elements + cout << "Enter elements:" << endl; + for(int i = 0; i> arr[i]; + } + cout << "Array before Sorting: "; + display(arr, n); + bubbleSort(arr, n); + cout << "Array after Sorting: "; + display(arr, n); } \ No newline at end of file diff --git a/Python/Web Scrapping/BeautifulSoup.py b/Python/Web Scrapping/BeautifulSoup.py new file mode 100644 index 0000000..3f61777 --- /dev/null +++ b/Python/Web Scrapping/BeautifulSoup.py @@ -0,0 +1,104 @@ +# HTML Web Scrapping using bs4 + +# STEP0: SETTING UP THE ENVIRONMENT + # Imported requests and beutifulSoup(bs4) + +import requests +from bs4 import BeautifulSoup +url = "https://codewithharry.com/" + +# STEP1: GET THE HTML + +r = requests.get(url) +htmlcontent = r.content +print(htmlcontent) + +# STEP2: PARSE THE HTML + +soup = BeautifulSoup(htmlcontent, 'html.parser') +print(soup.prettify) + +# STEP3: HTML TREE TRAVERSAL + #Tag + #Navigable String + #BeautifulSoup + #Comment + +title = soup.title + print(title) + +paras = soup.find_all('p') + print(paras) + +anchors = soup.find_all('a') + print(anchors) + +first_para = soup.find('p') + print(first_para) + +# Get classes of any element in HTML Page +print(first_para['class']) + +# Get all the elements of a specific class(eg. lead) +print(soup.find_all("p", class_="lead")) + +# To get text from tags/soup +print(soup.find('p').get_text()) +print(soup.get_text()) + +# To get all links of a page +anchors = soup.find_all('a') +all_links = set() + +for link in anchors: + if(link.get('href') != "#"): + linkText = "https://codewithharry.com" + link.get('href') + all_links.add(link) + print(linkText) + + +# For comment in HTML Tree Traversal + +markup = "

" +soup2 = BeautifulSoup(markup) +print(soup2.p.string) + + +# To find elements of a particular id + +navbarSupportedContent = soup.find(id='navbarSupportedContent') +for element in navbarSupportedContent.children: # we can use .contents also but for large websites .children is more effecient + print(element) + +for item in navbarSupportedContent.strings: + print(item) + +for item in navbarSupportedContent.stripped_strings: + print(item) + +print(navbarSupportedContent.parent) + +for item in navbarSupportedContent.parents: + print(item.name) + +# Sibblings + +print(navbarSupportedContent.next_sibling) + +print(navbarSupportedContent.next_sibling.next_sibling) + +print(navbarSupportedContent.previous_sibling) + +print(navbarSupportedContent.previous_sibling.previous_sibling) + +# CSS Selecting + +# # is for id + +id_element = soup.select('#loginModal') +print(id_element) + +# . is for class + +class_element = soup.select('.loginModal') +print(class_element) \ No newline at end of file From 9b49fa1554775d4992321832cc90045537ce993b Mon Sep 17 00:00:00 2001 From: SARTHAK ASTHANA Date: Fri, 23 Oct 2020 16:34:35 +0530 Subject: [PATCH 2/2] Requested Changes are made --- C++/Bubble_Sort.cpp | 33 --------------------------------- C++/bubble_sort.cpp | 41 ----------------------------------------- 2 files changed, 74 deletions(-) delete mode 100644 C++/Bubble_Sort.cpp delete mode 100644 C++/bubble_sort.cpp diff --git a/C++/Bubble_Sort.cpp b/C++/Bubble_Sort.cpp deleted file mode 100644 index 37f44ba..0000000 --- a/C++/Bubble_Sort.cpp +++ /dev/null @@ -1,33 +0,0 @@ -using namespace std; - -int main() -{ - int n, i, j, temp; - cout << "Enter the number of elements" << endl; - cin >> n; - int arr[n]; - for (i = 0; i < n; i++) - { - cout << "Enter " << i + 1 << " th element"; - cin >> arr[i]; - } - - for (i = n; i > 0; i--) - { - for (j = 0; j < i - 1; j++) - { - if (arr[j] > arr[j + 1]) - { - temp = arr[j]; - arr[j] = arr[j + 1]; - arr[j + 1] = temp; - } - } - } - cout << "\nSorted Elements are\n"; - for (i = 0; i < n; i++) - { - cout << arr[i] << " "; - } - return 0; -} diff --git a/C++/bubble_sort.cpp b/C++/bubble_sort.cpp deleted file mode 100644 index 89d627c..0000000 --- a/C++/bubble_sort.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -using namespace std; -void swapping(int &a, int &b) { //swap the content of a and b - int temp; - temp = a; - a = b; - b = temp; -} -void display(int *array, int size) { - for(int i = 0; i array[j+1]) { //when the current item is bigger than next - swapping(array[j], array[j+1]); - swaps = 1; //set swap flag - } - } - if(!swaps) - break; // No swap in this pass, so array is sorted - } -} -int main() { - int n; - cout << "Enter the number of elements: "; - cin >> n; - int arr[n]; //create an array with given number of elements - cout << "Enter elements:" << endl; - for(int i = 0; i> arr[i]; - } - cout << "Array before Sorting: "; - display(arr, n); - bubbleSort(arr, n); - cout << "Array after Sorting: "; - display(arr, n); -} \ No newline at end of file