import requests
from bs4 import BeautifulSoup
def get_company_address(company_name):
url = f"https://aiqicha.baidu.com/s?q={company_name}"
response = requests.get(url)
if response.status_code == 200:
soup = BeautifulSoup(response.content, 'html.parser')
# 解析网页内容,获取企业地址
address_element = soup.find(class_='company-info-text')
if address_element:
address = address_element.text.strip()
return address
return None
# 测试示例
company_name = "CSDN"
address = get_company_address(company_name)
if address:
print(f"企业地址:{address}")
else:
print("未找到相关信息")
python爬取地址
于 2023-10-07 11:30:20 首次发布