Created
December 6, 2022 22:40
-
-
Save harry-stark/4619edd4b7f2d8dd00590384dfcc08ef to your computer and use it in GitHub Desktop.
- Download csv from here https://docs.google.com/spreadsheets/d/1IFAzAM3EZgYPgTU11NLb_TaPvjCsxdIFRdhp2169PtQ/edit#gid=0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from urllib.parse import urlparse | |
df=pd.read_csv() | |
def url_matches_dataframe(url: str, df: pd.DataFrame) -> bool: | |
# Parse the given URL to get the netloc and hostname | |
parsed_url = urlparse(url) | |
netloc = parsed_url.netloc | |
hostname = parsed_url.hostname | |
# Remove "www" from the netloc and hostname | |
netloc = netloc.replace("www.", "") | |
hostname = hostname.replace("www.", "") | |
# Use the `isin` method to check if the given netloc or hostname is in the dataframe | |
return df['netloc'].isin([netloc]).any() | df['hostname'].isin([hostname]).any() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment