Welcome on my blog

We use cookies to ensure you get the best experience on our website.

Python – Pobieranie zabezpieczonej strony www login/haslo

Autor: chmajster 24.08.2023

Wymagania

pip3 install requests
pip3 install beautifulsoup4

Kod

import requests
from bs4 import BeautifulSoup

username = 'your_username'
password = 'your_password'
url = 'https://example.com/protected_page'

response = requests.get(url, auth=(username, password))
if response.status_code == 200:
    soup = BeautifulSoup(response.content, 'html.parser')

    main_div = soup.find('div', id='main-div')
    if main_div:
        link_tags = main_div.find_all('a', href=True)
        for link_tag in link_tags:
            link_url = link_tag['href']
            print(f"Found URL: {link_url}")
    else:
        print("No div with id 'main-div' found.")
else:
    print(f"Error: {response.status_code}")

Zawierajacy STRING

import requests
from bs4 import BeautifulSoup
from urllib.parse import urlparse

username = 'your_username'
password = 'your_password'
url = 'https://example.com/protected_page'

response = requests.get(url, auth=(username, password))
if response.status_code == 200:
    soup = BeautifulSoup(response.content, 'html.parser')

    main_div = soup.find('div', id='main-div')
    if main_div:
        link_tags = main_div.find_all('a', href=True)
        for link_tag in link_tags:
            link_url = link_tag['href']

            if 'wiki' in link_url or not urlparse(link_url).netloc:
                print(f"Found URL: {link_url}")
    else:
        print("No div with id 'main-div' found.")
else:
    print(f"Error: {response.status_code}")
Tagi:
Dodaj komentarz

Search
Categories
O Blogu

Cześć Podróżniku!

Ta strona ma nie być typowym poradnikiem w IT, Głównym jej cel to zapisanie krótkich notatek, które mogą się przydać w codziennym życiu podczas korzystania/konfiguracji różnych urządzeń np. Ustawienia DHCP na Routerze Cisco, Ustawieniu Karty sieciowej na Linuxie itp.

Buy me A coffee
[Empty]

Wszelkie prawa zastrzeżone