C++代码 用于爬虫的请求头部
将头部信息复制后,运行程序即可打包成python语言的字典形式
#include<iostream>
#include<string>
using namespace std ;
string ans[105] ;
int cnt = 0 ;
string make(string str){
string ss = "head[\"" ;
int coun = 0 ;
for(int i = 0 ; i < str.size() ; i++){
if(str[i] != ':') ss += str[i] ;
else{
i++ ; // Ìø¹ý¿Õ¸ñ
ss += "\"] = \"" ;
ss += str.substr( i + 1 , str.size() - 1 ) ;
ss += '"' ;
break ;
}
}
return ss ;
}
int main(){
int n ;
cin >> n ;
for(int i = 0 ; i < n + 1 ; i++){
string s ;
getline(cin , s) ;
ans[cnt++] = make(s) ;
}
for(int i = 0 ; i < cnt ; i++)
cout << ans[i] << endl ;
return 0 ;
}
/*
*/