adjusted search logic( by sources )
This commit is contained in:
@@ -554,7 +554,7 @@ if __name__ == '__main__':
|
||||
"bool":{
|
||||
"must":{
|
||||
"match_phrase": {
|
||||
"uri": url
|
||||
"sources": url
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -50,12 +50,12 @@ class News(BaseModel):
|
||||
result:List[NewsItem]
|
||||
|
||||
|
||||
es_home = Elasticsearch('http://localhost:9200', basic_auth=('elastic', '+JFa3xVIF0g_YAhpgTLl'), request_timeout=60, max_retries=5, retry_on_timeout=True)
|
||||
#es = Elasticsearch('http://localhost:9200', basic_auth=('elastic', '+JFa3xVIF0g_YAhpgTLl'), request_timeout=60, max_retries=5, retry_on_timeout=True)
|
||||
es = Elasticsearch('https://inse.nes.uni-due.de:443/elastic', basic_auth=('elastic', 'RLldUaJgbGeoqd3KCX3p'), request_timeout=60, max_retries=5, retry_on_timeout=True)
|
||||
|
||||
ude_organization_categorized = "ude_organization_categorized"
|
||||
|
||||
new_index_name = "testing_structure"
|
||||
new_index_name = "ude_organization_content"
|
||||
total_succeeds = 0
|
||||
total_failures = 0
|
||||
|
||||
@@ -550,8 +550,8 @@ def check_elastic_status(index_name):
|
||||
|
||||
}
|
||||
try:
|
||||
if not es_home.indices.exists(index=index_name):
|
||||
es_home.indices.create(index=index_name, mappings=mappings, settings=settings)
|
||||
if not es.indices.exists(index=index_name):
|
||||
es.indices.create(index=index_name, mappings=mappings, settings=settings)
|
||||
print(f"INDEX {index_name} created...")
|
||||
else:
|
||||
print(f"INDEX {index_name} already exists...")
|
||||
@@ -582,9 +582,9 @@ if __name__ == '__main__':
|
||||
#get urls to work with
|
||||
uploaded_urls = [org['uri'] for org in uploaded_orgs]
|
||||
print('Uploaded orgs:',uploaded_orgs)
|
||||
hierarchy_orgs = get_urls(path_to_hierarchy=sys.argv[1])[50:60]
|
||||
hierarchy_orgs = get_urls(path_to_hierarchy=sys.argv[1])
|
||||
urls = [url for url in hierarchy_orgs if url not in uploaded_urls]
|
||||
|
||||
|
||||
#extracting content
|
||||
failedPages = []
|
||||
if (check_elastic_status(new_index_name)):
|
||||
@@ -596,7 +596,7 @@ if __name__ == '__main__':
|
||||
"bool":{
|
||||
"must":{
|
||||
"match_phrase": {
|
||||
"uri": url
|
||||
"sources": url
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -659,7 +659,7 @@ if __name__ == '__main__':
|
||||
print(f'Organization data cleaned. Staff: {len(organization["staff"])}, Projects: {len(organization["projects"])}, News: {len(organization["news"])}')
|
||||
#print('Organization below:')
|
||||
#print(organization)
|
||||
es_home.index(index=new_index_name, document=organization)
|
||||
es.index(index=new_index_name, document=organization)
|
||||
print('Organization uploaded.')
|
||||
|
||||
uploaded_orgs.append({"uri":organization['uri']})
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ from pydantic import BaseModel, model_validator
|
||||
import pydantic
|
||||
from typing import List
|
||||
|
||||
#es_home = Elasticsearch('http://localhost:9200', basic_auth=('elastic', '+JFa3xVIF0g_YAhpgTLl'), request_timeout=60, max_retries=5, retry_on_timeout=True)
|
||||
#es = Elasticsearch('http://localhost:9200', basic_auth=('elastic', '+JFa3xVIF0g_YAhpgTLl'), request_timeout=60, max_retries=5, retry_on_timeout=True)
|
||||
es = Elasticsearch('https://inse.nes.uni-due.de:443/elastic', basic_auth=('elastic', 'RLldUaJgbGeoqd3KCX3p'), request_timeout=60, max_retries=5, retry_on_timeout=True)
|
||||
|
||||
URL = "https://project.nes.uni-due.de/llm1/v1/chat/completions"
|
||||
|
||||
@@ -1,522 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"INDEX ude_pages already exists...\n",
|
||||
"+++++++DIR: warc_zips\\ude-20240920104108-00000-voxel.warc.gz\n",
|
||||
"Searching file warc_zips\\ude-20240920104108-00000-voxel.warc.gz\n",
|
||||
"text/plain\n",
|
||||
"b'# robots.txt file\\n# Bans all robots from listed directories\\n\\n#User-agent: *\\n#Disallow: /~ht0209/lab2014/\\n#Disallow: /~bi0058/\\n#Disallow: /cms/zs-2001/htdocs/\\n#Disallow: /imp/zs-2001/htdocs/\\n\\nUser-agent: bingbot\\n#Disallow: /~ht0209/lab2014/\\n#Disallow: /~bi0058/\\nCrawl-delay: 10\\n\\nUser-agent: GPTBot\\nDisallow: /\\n'\n",
|
||||
"\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n",
|
||||
"#######################################\n",
|
||||
"persisting...\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import warcio\n",
|
||||
"import sys\n",
|
||||
"import bs4\n",
|
||||
"import langdetect \n",
|
||||
"import trafilatura\n",
|
||||
"import os\n",
|
||||
"import json\n",
|
||||
"import re\n",
|
||||
"import time\n",
|
||||
"import html\n",
|
||||
"from elasticsearch import Elasticsearch\n",
|
||||
"import yake\n",
|
||||
"#inse elastic instance\n",
|
||||
"#es = Elasticsearch('https://inse.nes.uni-due.de:443/elastic', basic_auth=('elastic', 'RLldUaJgbGeoqd3KCX3p'), request_timeout=60, max_retries=5, retry_on_timeout=True)\n",
|
||||
"#es = Elasticsearch({'host':'localhost', 'port': 9200, 'scheme': 'http'})\n",
|
||||
"es = Elasticsearch('http://localhost:9200',verify_certs=True, basic_auth=('elastic', '+JFa3xVIF0g_YAhpgTLl'), max_retries=5, retry_on_timeout=True)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"index_name = \"ude_pages\"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def check_elastic_status():\n",
|
||||
" if not es.ping():\n",
|
||||
" print(\"Elasticsearch connection not found\")\n",
|
||||
" return False\n",
|
||||
" \n",
|
||||
" #if es.indices.exists(index=index_name):\n",
|
||||
" # es.indices.delete(index=index_name, ignore=[400, 404])\n",
|
||||
" \n",
|
||||
" settings = {\n",
|
||||
" \"analysis\": {\n",
|
||||
" \"analyzer\": {\n",
|
||||
" \"customanalyzer\": {\n",
|
||||
" \"type\": \"custom\",\n",
|
||||
" \"tokenizer\": \"standard\",\n",
|
||||
" \"filter\": [\n",
|
||||
" \"lowercase\",\n",
|
||||
" \"asciifolding\"\n",
|
||||
" ]\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" mappings = {\n",
|
||||
" \n",
|
||||
" \"properties\": {\n",
|
||||
" \"uri\": {\n",
|
||||
" \"type\": \"text\",\n",
|
||||
" \"fields\": {\n",
|
||||
" \"keyword\": { \n",
|
||||
" \"type\": \"keyword\"\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" },\n",
|
||||
" \"domain\": {\n",
|
||||
" \"type\": \"keyword\"\n",
|
||||
" },\n",
|
||||
" \"subdomain\": {\n",
|
||||
" \"type\": \"keyword\"\n",
|
||||
" }, \n",
|
||||
" \"path\": {\n",
|
||||
" \"type\": \"text\",\n",
|
||||
" \"fields\": {\n",
|
||||
" \"keyword\": { \n",
|
||||
" \"type\": \"keyword\"\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" },\n",
|
||||
" \"query\": {\n",
|
||||
" \"type\": \"text\",\n",
|
||||
" \"fields\": {\n",
|
||||
" \"keyword\": { \n",
|
||||
" \"type\": \"keyword\"\n",
|
||||
" }\n",
|
||||
" }\n",
|
||||
" },\n",
|
||||
" \"host\": {\n",
|
||||
" \"type\": \"keyword\"\n",
|
||||
" },\n",
|
||||
" \"body\": {\n",
|
||||
" \"type\": \"text\",\n",
|
||||
" \"analyzer\": \"customanalyzer\",\n",
|
||||
" \"search_analyzer\": \"customanalyzer\"\n",
|
||||
" },\n",
|
||||
" \"lang\": {\n",
|
||||
" \"type\": \"keyword\"\n",
|
||||
" },\n",
|
||||
" \"tags\": {\n",
|
||||
" \"type\": \"nested\",\n",
|
||||
" \"properties\": {\n",
|
||||
" \"value\": { \"type\": \"keyword\" },\n",
|
||||
" \"score\": { \"type\": \"double\" }\n",
|
||||
" }\n",
|
||||
" },\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" }\n",
|
||||
" try:\n",
|
||||
" if not es.indices.exists(index=index_name):\n",
|
||||
" es.indices.create(index=index_name, mappings=mappings, settings=settings)\n",
|
||||
" print(f\"INDEX {index_name} created...\")\n",
|
||||
" else:\n",
|
||||
" print(f\"INDEX {index_name} already exists...\")\n",
|
||||
" \n",
|
||||
" \n",
|
||||
" except Exception as e:\n",
|
||||
" print(\"failed to create index mapping\") \n",
|
||||
" print(e) \n",
|
||||
" return False\n",
|
||||
" \n",
|
||||
" return True\n",
|
||||
"\n",
|
||||
"def getGroups(match):\n",
|
||||
" uri={'protocol':\"\",\n",
|
||||
" 'subdomain':\"\",\n",
|
||||
" 'domain':\"\",\n",
|
||||
" 'port':\"\",\n",
|
||||
" 'path':\"\",\n",
|
||||
" 'query':\"\"}\n",
|
||||
" if match:\n",
|
||||
" uri['protocol'] = match.group(1) if match.group(1) else \"\"\n",
|
||||
" uri['subdomain'] = match.group(2) if match.group(2) else \"\"\n",
|
||||
" uri['domain'] = match.group(3) if match.group(3) else \"\"\n",
|
||||
" uri['port'] = match.group(4) if match.group(4) else \"\"\n",
|
||||
" uri['path'] = match.group(5) if match.group(5) else \"\"\n",
|
||||
" uri['query'] = match.group(6) if match.group(6) else \"\"\n",
|
||||
"\n",
|
||||
" return uri\n",
|
||||
"\n",
|
||||
" \n",
|
||||
"def process_file(filename,total_records):\n",
|
||||
" print(\"Searching file\", filename)\n",
|
||||
" records = 0\n",
|
||||
" bodies = []\n",
|
||||
" regex_for_link_parts = r'^(\\w+):\\/\\/(?:((?:[^\\/:.]+\\.)+))?([^\\/:.]+(?:\\.[^\\/:.]+)+)(?::(\\d+))?(\\/[^?#]*)?(\\?[^#]*)?(#.*)?$'\n",
|
||||
" with open(filename, 'rb') as stream:\n",
|
||||
" for record in warcio.ArchiveIterator(stream):\n",
|
||||
" if total_records < 100000:\n",
|
||||
" if record.rec_type == 'response':\n",
|
||||
" content_type = record.http_headers.get_header('Content-Type')\n",
|
||||
" if not bool(content_type):\n",
|
||||
" continue\n",
|
||||
" if 'text/html' in content_type.lower():\n",
|
||||
" tokens = content_type.split(\";\")\n",
|
||||
" encoding = \"iso-8859-1\"\n",
|
||||
" for token in tokens:\n",
|
||||
" trimmed = token.strip()\n",
|
||||
" if trimmed.startswith(\"charset=\"):\n",
|
||||
" encoding = trimmed[8:].lower()\n",
|
||||
"\n",
|
||||
" try:\n",
|
||||
" decoded = record.content_stream().read().decode(encoding)\n",
|
||||
" except:\n",
|
||||
" continue\n",
|
||||
" \n",
|
||||
" text = trafilatura.extract(decoded, output_format=\"txt\")\n",
|
||||
" try:\n",
|
||||
" lang = langdetect.detect(text)\n",
|
||||
" except:\n",
|
||||
" lang = ''\n",
|
||||
" try:\n",
|
||||
" title = html.unescape(re.search(r\"<title>(.*?)<\\/title>\", decoded).group(1))\n",
|
||||
" except:\n",
|
||||
" title=''\n",
|
||||
" keywords = []\n",
|
||||
" if lang == \"de\":\n",
|
||||
" keyword_extractor = yake.KeywordExtractor(\n",
|
||||
" dedupFunc=\"seqm\", \n",
|
||||
" dedupLim=0.9,\n",
|
||||
" top=15, \n",
|
||||
" lan=\"de\")\n",
|
||||
" yake_keywords = keyword_extractor.extract_keywords(text)\n",
|
||||
"\n",
|
||||
" else:\n",
|
||||
" keyword_extractor = yake.KeywordExtractor( \n",
|
||||
" dedupFunc=\"seqm\", \n",
|
||||
" dedupLim=0.9,\n",
|
||||
" top=15, \n",
|
||||
" lan=\"en\")\n",
|
||||
" yake_keywords = keyword_extractor.extract_keywords(text)\n",
|
||||
" keywords = [{'value':x[0],'score':x[1]} for x in yake_keywords]\n",
|
||||
" if lang == \"en\" or lang == 'de':\n",
|
||||
" total_records += 1\n",
|
||||
" print(\"#######################################\")\n",
|
||||
" \n",
|
||||
" # print(record.rec_headers.get_header('WARC-Target-URI'))\n",
|
||||
" # print(text)\n",
|
||||
" \n",
|
||||
" lower = text.lower()\n",
|
||||
" uri = record.rec_headers.get_header('WARC-Target-URI')\n",
|
||||
" match = re.search(regex_for_link_parts, uri)\n",
|
||||
"\n",
|
||||
" uri_parts = getGroups(match)\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" lower = lower.replace('\\r', '')\n",
|
||||
" lower = lower.rstrip()\n",
|
||||
" \n",
|
||||
" print(\"persisting...\")\n",
|
||||
" \n",
|
||||
" element = {}\n",
|
||||
" element['uri'] = uri\n",
|
||||
" element['protocol'] = uri_parts['protocol']\n",
|
||||
" element['subdomain'] = uri_parts['subdomain'].replace('www.','')\n",
|
||||
" element['domain'] = uri_parts['domain']\n",
|
||||
" element['port'] = uri_parts['port']\n",
|
||||
" element['path'] = uri_parts['path']\n",
|
||||
" element['query'] = uri_parts['query']\n",
|
||||
" element['title'] = title\n",
|
||||
" element['body'] = lower\n",
|
||||
" element['lang'] = lang\n",
|
||||
" element['keywords'] = keywords\n",
|
||||
" #element['year'] = int(filename[filename.find(\"CC-NEWS-\") + 8:filename.find(\"CC-NEWS-\") + 12])\n",
|
||||
"\n",
|
||||
" json_obj = json.dumps(element)\n",
|
||||
" try: \n",
|
||||
" es.index(index=index_name,body=json_obj) \n",
|
||||
" except Exception as e:\n",
|
||||
" print(\"upload failed....\")\n",
|
||||
" print(e) \n",
|
||||
" continue\n",
|
||||
" \n",
|
||||
" else:\n",
|
||||
" print(content_type)\n",
|
||||
" print(record.content_stream().read())\n",
|
||||
" print('')\n",
|
||||
" return total_records\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" # if (len(sys.argv) < 2):\n",
|
||||
" # print(\"Usage:\", sys.argv[0], \"<warc dir>*\")\n",
|
||||
" # exit(1)\n",
|
||||
" \n",
|
||||
" if check_elastic_status():\n",
|
||||
" start = time.perf_counter()\n",
|
||||
" total_records = 0\n",
|
||||
" for directory, subdirectories, files in os.walk('warc_zips'):\n",
|
||||
" for file in files[:1]:\n",
|
||||
" full_file_dir = os.path.join(directory, file)\n",
|
||||
" print(\"+++++++DIR: \", full_file_dir)\n",
|
||||
" total_records += process_file(full_file_dir,total_records)\n",
|
||||
" end = time.perf_counter()\n",
|
||||
" print(f\"Total records: {total_records}, within: {end-start:0.4f} seconds.\")\n",
|
||||
"\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"<re.Match object; span=(0, 80), match='https://new.example.com:8080/articles/penis/yes?d>\n",
|
||||
"{'protocol': 'https', 'subdomain': 'new.', 'domain': 'example.com', 'port': '8080', 'path': '/articles/penis/yes', 'query': '?da?id=123&category=tech'}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import re\n",
|
||||
"\n",
|
||||
"# URL to extract parts from\n",
|
||||
"url = \"https://new.example.com:8080/articles/penis/yes?da?id=123&category=tech#section1\"\n",
|
||||
"\n",
|
||||
"# Regex pattern to extract URL components\n",
|
||||
"pattern = r'^(\\w+):\\/\\/(?:((?:[^\\/:.]+\\.)+))?([^\\/:.]+(?:\\.[^\\/:.]+)+)(?::(\\d+))?(\\/[^?#]*)?(\\?[^#]*)?(#.*)?$'\n",
|
||||
"def getGroups(match):\n",
|
||||
" uri={'protocol':\"\",\n",
|
||||
" 'subdomain':\"\",\n",
|
||||
" 'domain':\"\",\n",
|
||||
" 'port':\"\",\n",
|
||||
" 'path':\"\",\n",
|
||||
" 'query':\"\"}\n",
|
||||
" if match:\n",
|
||||
" uri['protocol'] = match.group(1) if match.group(1) else \"\"\n",
|
||||
" uri['subdomain'] = match.group(2) if match.group(2) else \"\"\n",
|
||||
" uri['domain'] = match.group(3) if match.group(3) else \"\"\n",
|
||||
" uri['port'] = match.group(4) if match.group(4) else \"\"\n",
|
||||
" uri['path'] = match.group(5) if match.group(5) else \"\"\n",
|
||||
" uri['query'] = match.group(6) if match.group(6) else \"\"\n",
|
||||
"\n",
|
||||
" return uri\n",
|
||||
" \n",
|
||||
"# Apply the regex pattern\n",
|
||||
"\n",
|
||||
"match = re.search(pattern, url)\n",
|
||||
"print(match)\n",
|
||||
"uri = getGroups(match)\n",
|
||||
"\n",
|
||||
"print(uri)"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "ies",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.20"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Reference in New Issue
Block a user