删除URL后面的所有字符?

2024-04-25 12:38:15 发布

您现在位置:Python中文网/ 问答频道 /正文

基本上,我正在尝试删除URL中URL扩展名之后的所有字符,但事实证明这很困难。这个应用程序使用各种扩展名列出各种url。你知道吗

以下是我的消息来源:

import requests
from bs4 import BeautifulSoup
from time import sleep

#takes userinput for path of panels they want tested
import_file_path = input('Enter the path of the websites to be tested: ')

#takes userinput for path of exported file
export_file_path = input('Enter the path of where we should export the  panels to: ')

#reads imported panels
with open(import_file_path, 'r') as panels:
    panel_list = []
    for line in panels:
        panel_list.append(line)

x = 0

for panel in panel_list:
    url = requests.get(panel)
    soup = BeautifulSoup(url.content, "html.parser")
    forms = soup.find_all("form")
    action = soup.find('form').get('action')

    values = { 
    soup.find_all("input")[0].get("name") : "user",
    soup.find_all("input")[1].get("name") : "pass"
    }


    print(values)

    r = requests.post(action, data=values)
    print(r.headers)
    print(r.status_code)
    print(action)
    sleep(10)
    x += 1

我试图实现的是一个应用程序,它可以从文本文档中提供的url列表中自动测试您的用户名/密码。但是,BeautifulSoup在爬网操作标记时返回一个不完整的URL,也就是说,它不会返回完整的http://example.com/action.php动作.php就像在密码里一样。我能想到的唯一方法是将'action'变量重新声明为'panel',删除url扩展名后的所有字符,然后是'action'。你知道吗

谢谢!你知道吗


Tags: ofthepathimporturlforinputget

热门问题