前天看了别人的爬虫https://www.52pojie.cn/thread-1359373-1-1.html
PHP的,不会用,无聊时改成python试试
[Python] 纯文本查看 复制代码 # -*- coding: utf-8 -*-
import requests
import json
import urllib
import re
from faker import Faker
fake = Faker()
header={'User-Agent': fake.user_agent()}
name = input("请输入公司名称")
data = urllib.parse.quote(str(name))
url = 'https://aiqicha.baidu.com'
url1='https://aiqicha.baidu.com/s?q='+data+'&t=0'
s= requests.Session()
res1 = s.get(url = url,headers =header)
res2 = s.post(url = url1,headers =header)
pattern = 'pid\":\"(\d{14})'
rel = re.findall(pattern,res2.text)
detail_url='https://aiqicha.baidu.com/detail/basicAllDataAjax?pid='+rel[0] #只爬第一个,想要爬取的话加循环
res3 = s.get(url= detail_url,headers = header)
res3.text.encode('utf-8').decode('unicode_escape')
result = json.loads(res3.text) #返回的企业信息JSON串 可以根据自己需要提取
|