帮我用python写一个这个网址https://www.qcc.com/在输入框内输入任意企业名称可以获得企业名称和地址的爬虫 
时间: 2023-06-03 19:07:03 浏览: 27
很高兴为您服务!以下是Python爬虫程序,可以输入任意企业名称并获取企业名称和地址:
```python
import requests
from bs4 import BeautifulSoup
# 输入你想查询的企业名称
company_name = input("请输入你想查询的企业名称:")
# 构建URL
url = "https://www.qcc.com/search?key=" + company_name
# 请求网页并获取html内容
html = requests.get(url).content
# 解析html内容
soup = BeautifulSoup(html, 'html.parser')
company_list = soup.find_all(class_='list-group-item clearfix')
# 遍历企业列表并输出企业名称和地址
for company in company_list:
company_info = company.find(class_='text-primary').get_text().strip() + " " + company.find(class_='text-muted').get_text().strip()
print(company_info)
```
请注意,此爬虫程序具有一定的局限性,如果你搜索的企业名称不够准确,可能无法得到相应的结果。
相关问题
用python写一个这个https://www.qcc.com/firm/f1c5372005e04ba99175d5fd3db7b8fc.html网址的爬虫要求获取名称和地址
好的,我可以为您编写一个Python爬虫来获取指定网址上的公司名称和地址。以下是代码示例:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://www.qcc.com/firm/f1c5372005e04ba99175d5fd3db7b8fc.html'
headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
company_name = soup.find('a', attrs={'class': 'ma_h1'}).text.strip()
company_address = soup.find('td', attrs={'data-header': '所在地'}).text.strip()
print('公司名称:{}'.format(company_name))
print('公司地址:{}'.format(company_address))
```
请注意,这个爬虫只适用于特定的URL,如果您需要获取其他网站的信息,需要对代码进行相应的修改。
企查查 python 爬虫 搜索
您可以使用Python编写爬虫来进行企查查网站的搜索。以下是一个简单的示例代码:
```python
import requests
def qcc_search(keyword):
url = f'https://www.qcc.com/search?key={keyword}'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36'
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
# 这里可以根据返回的页面内容进行相应的解析操作,提取所需的信息
print(response.text)
else:
print('请求失败')
qcc_search('python爬虫')
```
这段代码使用`requests`库发送GET请求,模拟浏览器访问企查查搜索页面。您可以根据返回的页面内容进行相应的解析操作,提取所需的信息。请注意,为了模拟浏览器的请求,代码中添加了`User-Agent`头部信息。
需要注意的是,爬取网站信息时请遵守相关法律法规和网站的访问规则,不要过度请求或滥用爬虫。
相关推荐





抱歉,看起来您遇到了JSON解析错误。这可能是因为企查查返回的结果不是有效的JSON格式,导致解析失败。为了解决这个问题,您可以尝试使用其他方式来解析返回的数据。
一种方法是使用正则表达式来提取所需的信息。您可以根据返回的页面内容使用正则表达式模式进行匹配和提取。例如,如果您想要提取企业名称和法人信息,可以尝试以下代码:
python
import requests
import re
def qcc_search(keyword):
url = f'https://www.qcc.com/search?key={keyword}'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36'
}
response = requests.get(url, headers=headers)
if response.status_code == 200:
# 使用正则表达式匹配企业名称和法人信息
pattern = r'(.*?).*?(.*?)'
result = re.findall(pattern, response.text)
for item in result:
company_id = item[0]
company_name = item[1]
legal_person = item[2]
print(f"企业ID: {company_id}")
print(f"企业名称: {company_name}")
print(f"法人: {legal_person}")
print('----------------------')
else:
print('请求失败')
qcc_search('python爬虫')
这段代码使用正则表达式模式(.*?).*?(.*?)来匹配企业名称和法人信息。您可以根据需要修改正则表达式模式,并使用re.findall()函数进行匹配和提取。
请注意,正则表达式可能会比较复杂且容易出错,需要根据具体的网页结构进行调整。另外,使用正则表达式提取信息时,需要注意处理可能存在的异常情况。
希望这可以帮助您解决问题。如果问题仍然存在,请提供更多的错误信息,以便我可以更好地帮助您。











