Python 3.x 如何使用python3从URL修改字段

Python 3.x 如何使用python3从URL修改字段,python-3.x,Python 3.x,大家好,我需要使用pthon3脚本修改URL。例如,这里有一个“我的脚本输出”,我想从我的输出中删除“include.php”。所以我想输出为“http://10.10.10.5/dvwa/vulnerabilities/fi/?page=“我该怎么办呢 import requests from bs4 import BeautifulSoup from urllib.request import urlparse, urljoin url = "http://10.10.10.5

大家好,我需要使用pthon3脚本修改URL。例如,这里有一个“我的脚本输出”,我想从我的输出中删除“include.php”。所以我想输出为“http://10.10.10.5/dvwa/vulnerabilities/fi/?page=“我该怎么办呢

import requests
from bs4 import BeautifulSoup
from urllib.request import urlparse, urljoin

url  = "http://10.10.10.5/dvwa/index.php"

cookies = {'security' : 'low', 'PHPSESSID':'ev5mlspqdiklrgaqfqbh00act0'}

r = requests.post(url, cookies = cookies)

soup = BeautifulSoup(r.text, 'lxml')

for link in soup.findAll('a', href = True):

    href_csrf = (link['href'])

    if "fi" in href_csrf:

        csrf_url = urljoin(url, href_csrf)

        print("Found fi : ", csrf_url)
你可以这样做。 在这里,你可以将你不想要的零件替换为零

url = "http://10.10.10.5/dvwa/vulnerabilities/fi/?page=include.php"

url = url.replace("include.php", "")

print(url)