by Guest » 18 Jan 2025, 22:46
Ich habe eine CSV-Datei mit einer Liste von Unternehmen, mit Spalten für „Firmenname“ und „Firmen-URL“. Ich möchte die Kontakttelefonnummern dieser Unternehmen anhand ihrer URLs extrahieren. Kann mir bitte jemand eine Lösung dafür geben?
Code: Select all
import pandas as pd
import requests
from bs4 import BeautifulSoup
# Provide the absolute path
file_path = r'D:\VS CODE\scrap_tool\Company_list-1.csv'
df = pd.read_csv(file_path)
print(df.head(5))
print(df.columns)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'
}
def get_contact_number(url):
try:
# Fetch the website content
headers = {'User-Agent': 'Mozilla/5.0'}
response = requests.get(url, headers=headers, timeout=10)
soup = BeautifulSoup(response.text, 'html.parser')
# Search for phone numbers using regex patterns
phone_numbers = set()
for text in soup.stripped_strings:
if '+91' in text or text.isdigit():
if len(text) >= 10 and len(text)
Ich habe eine CSV-Datei mit einer Liste von Unternehmen, mit Spalten für „Firmenname“ und „Firmen-URL“. Ich möchte die Kontakttelefonnummern dieser Unternehmen anhand ihrer URLs extrahieren. Kann mir bitte jemand eine Lösung dafür geben?
[code]import pandas as pd
import requests
from bs4 import BeautifulSoup
# Provide the absolute path
file_path = r'D:\VS CODE\scrap_tool\Company_list-1.csv'
df = pd.read_csv(file_path)
print(df.head(5))
print(df.columns)
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'
}
def get_contact_number(url):
try:
# Fetch the website content
headers = {'User-Agent': 'Mozilla/5.0'}
response = requests.get(url, headers=headers, timeout=10)
soup = BeautifulSoup(response.text, 'html.parser')
# Search for phone numbers using regex patterns
phone_numbers = set()
for text in soup.stripped_strings:
if '+91' in text or text.isdigit():
if len(text) >= 10 and len(text)