Przejdź do treści

Python – Pobieranie zabezpieczonej strony www login/haslo

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}")

Dodaj komentarz

Twój adres email nie zostanie opublikowany. Wymagane pola są oznaczone *