#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
#include <string.h>
#include <sstream>
#include <windows.h>
#include <shellapi.h>
#include <dos.h>
using namespace std;
char* initializestrings(char* s, int l)
{
for(int i=0;i<l;i++)
{
s[i]='\0';
}
return s;
}
string trim_spaces(const char* s)
{
string str; int y;
if(s[0] == ' ')
{
for(int i=0;i<strlen(s);i++)
{
if(s[i]==' ' && s[i+1] != ' ')
{
y=i+1;
break;
}
else
continue;
}
for(int i=y; i<strlen(s);i++)
str = str + s[i];
return str;
}
else
{
return str;
}
}
bool checkextraques(int a[], int x)
{
bool var = false;
for(int i=0;i<15;i++)
{
if(a[i]==x)
var = true;
}
return var;
}
string find_domain(string url)
{
int findslash;
findslash = url.find("/");
const char* temp = url.c_str();
url="";
for(int i=findslash+2;temp[i]!='/';i++)
{
url=url+temp[i];
}
return url;
}
int main()
{
int dwiterator = 0;
int siteoption =0;
char ch;
string tempqa[1000], res[200], resv[500];
char thumbnailurl[400];
int qi, ri; qi = 0; ri = 0;
ifstream html[5];
ofstream pythonscript[100];
do
{
string url,domain,ques,ans;
int quesloop, ansloop; quesloop =0; ansloop =0;
cout<<"Enter your URL\n";
cin>>url;
domain = find_domain(url);
string alloweddomains[] = {"www.playbuzz.com", "play.howstuffworks.com", "www.zoo.com",
"brainfall.com", "www.gotoquiz.com", "www.proprofs.com", "quizdoo.com", "altgalaxy.co",
"status4everyone.com", "www.magiquiz.com", "www.allthetests.com", "www.women.com"};
for(int i=0;i<12;i++)
{
if(domain==alloweddomains[i])
{
siteoption = i+1;
break;
}
}
if(siteoption==0)
{
cout<<"Domain: " <<domain<<" This domain is invalid\n";
exit(0);
}
if(siteoption == 1)
{
ques = "<p>";
ans = "text-viewer-wrapper\"";
quesloop = 1;
ansloop = 4;
}
if(siteoption == 2 || siteoption == 3)
{
ques = "title-tertiary\"";
ans = "answer answer-default\"";
quesloop = 1;
ansloop = 1;
}
if(siteoption == 4)
{
ques = "question_title\"";
ans = "answer noselect\"";
quesloop = 1;
ansloop = 1;
}
if(siteoption == 5)
{
ques = "<strong>";
ans = "type=\"radio\"";
quesloop = 1;
ansloop = 1;
}
if(siteoption == 6)
{
ques = "question-text\"";
ans = "opt_text\"";
quesloop = 1;
ansloop = 2;
}
if(siteoption == 7)
{
ques="qc-question-text\"";
ans="qc-answer-text\"";
quesloop = 1;
ansloop = 1;
}
if(siteoption == 8)
{
ques="wpvqgr-question-label\"";
ans="wpvqgr-answer-label\"";
quesloop=1;
ansloop=1;
}
if(siteoption == 9)
{
ques="snax-quiz-question-title\"";
ans="snax-quiz-answer-label-text\"";
quesloop=1;
ansloop=1;
}
if(siteoption == 10)
{
ques="question-title overlay\"";
ans="fa fa-check\"";
quesloop = 1;
ansloop = 3;
}
if(siteoption == 11)
{
ques="class=\"questions";
ans="class=\"answer\">";
quesloop = 8;
ansloop = 2;
}
if(siteoption == 12)
{
ques = "wdc_qc_caption_text\"";
ans = "wdc_qc_qtext\"";
quesloop = 1;
ansloop = 1;
}
pythonscript[dwiterator].open("pyparser.py");
string script = "from selenium import webdriver\nfrom selenium.webdriver.chrome.options import Options\noptions=Options()\nfrom time import sleep\nurl = \noptions.add_experimental_option( \"prefs\",{'profile.managed_default_content_settings.javascript': 2})\ndriver = webdriver.Chrome('C:/Users/USER/Desktop/chromedriver.exe', options=options)\ndriver.get(url)\nsleep(10)\nraw_html=driver.page_source\nfrom bs4 import BeautifulSoup as bs\nsoup = bs(raw_html,features='html.parser')\nprettyHTML = soup.prettify()\nopen('C:/Users/USER/Desktop/quiz.csv', 'w', encoding='utf-8')\nwith open('C:/Users/USER/Desktop/htmlparsing.txt', 'w', encoding='utf-8') as f:\n f.write(prettyHTML.replace('&', '&'))\n driver.quit()";
url.insert(0,"'");
url.append("'");
int findurl=script.find("url = ");
script.insert(findurl+6, url);
pythonscript[dwiterator]<<script;
pythonscript[dwiterator].close();
ShellExecuteA(NULL, "open", "pyparser.py", NULL, NULL, SW_SHOWNORMAL);
Sleep(40000);
html[dwiterator].open("htmlparsing.txt");
string line;
while(!html[dwiterator].eof())
{
line = "";
getline(html[dwiterator], line);
int y=0;
string x; x="";
int findques = 0;
findques = line.find(ques);
if(findques>0)
{
for(int i=1;i<=quesloop;i++)
{
line = "";
getline(html[dwiterator], line);
}
x=trim_spaces(line.c_str());
x.insert(0, "Q");
tempqa[qi] = x;
qi++;
y=1;
}
if(y==0)
{
int findans = 0;
findans = line.find(ans);
if(findans>0)
{
for(int i=1;i<=ansloop;i++)
{
line = "";
getline(html[dwiterator], line);
}
x=trim_spaces(line.c_str());
x.insert(0, "A");
tempqa[qi] = x;
qi++;
y=1;
}
}
}
html[dwiterator].close();
remove("pyparser.py");
remove("htmlparsing.txt");
Sleep(3000);
++dwiterator;
if(dwiterator<5)
{
cout<<"Do you want to continue? (Press 'Y' to continue and 'N' to exit)\n";
cin>>ch;
}
}
while(toupper(ch)!='N' && dwiterator<5);
int num_of_elements = sizeof(tempqa)/sizeof(tempqa[0]);
for(int i=0;i<num_of_elements;i++)
{
char ch,ch1;
ch = tempqa[i].c_str()[0];
if(i!=num_of_elements-1)
ch1 = tempqa[i+1].c_str()[0];
if(ch=='Q' && ch1=='Q')
{
for(int j=i;j<num_of_elements-1;j++)
{
tempqa[j]=tempqa[j+1];
}
}
}
ofstream allquestions;
allquestions.open("allquestions.txt");
for(int i=0;i<qi;i++)
{
char ch = tempqa[i].c_str()[0];
if(ch=='Q')
allquestions<<"Index of Question "<<i<<" "<<tempqa[i]<<"\n";
else
allquestions<<tempqa[i]<<"\n";
}
allquestions.close();
/*int allquestionsindex[15];
cout<<"Enter the index of all questions which you want to have:\n";
for(int i=0;i<15;i++)
cin>>allquestionsindex[i];*/
string mac[1000]; int y=0; int k=0;
for(int i=0;i<qi;i++)
{
char ch = tempqa[i].c_str()[0];
if(ch == 'Q' && k<15)
{
mac[y] = tempqa[i];
y++;
if(i<qi-1)
for(int j=i+1;tempqa[j].c_str()[0]=='A';j++)
{
mac[y]=tempqa[j];
y++;
}
k++;
}
}
int numofprsn;
char pd;
string dummy="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec fringilla placerat turpis eget imperdiet. Cras a dignissim tortor. Nunc et gravida nisi, et dignissim ex. Cras quis sem felis. Aenean ultricies finibus magna ut interdum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aenean et.";
cout<<"How many personalities are there?\n";
cin>>numofprsn;
cout<<"Do you want to enter the personality Description? (Enter 'Y' for Yes and 'N' for No)\n";
cin>>pd;
for(int i=1;i<=numofprsn;i++)
{
cout<<"Enter the personality\n";
fflush(stdin);
getline(cin, res[ri]);
res[ri]=res[ri].insert(0,"#");
ri++;
if(toupper(pd) == 'Y')
{
cout<<"Enter the personality description\n";
fflush(stdin);
getline(cin, res[ri]);
}
else
{
fflush(stdin);
res[ri]=dummy;
}
ri++;
}
int pi=0;
for(int i=0;i<y;i++)
{
const char* th=mac[i].c_str();
if(th[0]=='A')
{
string x;
x=th;
x.append(res[pi]);
mac[i]=x;
pi=pi+2;
if(pi==ri)
pi=0;
}
}
cout<<"Enter the post ID of this quiz\n";
long int postid;
cin>>postid;
ofstream csv;
string qcsv = "quiz.csv";
qcsv.insert(0,to_string(postid));
rename("quiz.csv", qcsv.c_str());
csv.open(qcsv);
for(int i=0;i<y;i++)
{
const char* rt; const char* rt1;
rt=mac[i].c_str();
if(i!=y-1)
rt1=mac[i+1].c_str();
if(rt[0]=='Q')
{
csv<<"question"<<"*";
string x;
x=mac[i].substr(1,mac[i].size()-1);
csv<<x<<"*";
}
if(rt[0]=='A')
{
if(rt1[0]=='Q')
{
string x;
x=mac[i].substr(1,mac[i].size()-1);
csv<<x<<"*";
csv<<"\n";
}
else
{
string x;
x=mac[i].substr(1,mac[i].size()-1);
csv<<x<<"*";
}
}
}
csv<<"\n";
for(int i=0;i<ri;i++)
{
if(i%2==0 && i!=1)
{
csv<<"answer"<<"*";
string x;
x=res[i].substr(1,res[i].size()-1);
csv<<x<<"*";
}
else
{
//string x;
//x=res[i].substr(1,res[i].size()-1);
csv<<res[i]<<"\n";
}
}
csv.close();
return 0;
}
#include <stdio.h>
#include <fstream>
#include <string>
#include <string.h>
#include <sstream>
#include <windows.h>
#include <shellapi.h>
#include <dos.h>
using namespace std;
char* initializestrings(char* s, int l)
{
for(int i=0;i<l;i++)
{
s[i]='\0';
}
return s;
}
string trim_spaces(const char* s)
{
string str; int y;
if(s[0] == ' ')
{
for(int i=0;i<strlen(s);i++)
{
if(s[i]==' ' && s[i+1] != ' ')
{
y=i+1;
break;
}
else
continue;
}
for(int i=y; i<strlen(s);i++)
str = str + s[i];
return str;
}
else
{
return str;
}
}
bool checkextraques(int a[], int x)
{
bool var = false;
for(int i=0;i<15;i++)
{
if(a[i]==x)
var = true;
}
return var;
}
string find_domain(string url)
{
int findslash;
findslash = url.find("/");
const char* temp = url.c_str();
url="";
for(int i=findslash+2;temp[i]!='/';i++)
{
url=url+temp[i];
}
return url;
}
int main()
{
int dwiterator = 0;
int siteoption =0;
char ch;
string tempqa[1000], res[200], resv[500];
char thumbnailurl[400];
int qi, ri; qi = 0; ri = 0;
ifstream html[5];
ofstream pythonscript[100];
do
{
string url,domain,ques,ans;
int quesloop, ansloop; quesloop =0; ansloop =0;
cout<<"Enter your URL\n";
cin>>url;
domain = find_domain(url);
string alloweddomains[] = {"www.playbuzz.com", "play.howstuffworks.com", "www.zoo.com",
"brainfall.com", "www.gotoquiz.com", "www.proprofs.com", "quizdoo.com", "altgalaxy.co",
"status4everyone.com", "www.magiquiz.com", "www.allthetests.com", "www.women.com"};
for(int i=0;i<12;i++)
{
if(domain==alloweddomains[i])
{
siteoption = i+1;
break;
}
}
if(siteoption==0)
{
cout<<"Domain: " <<domain<<" This domain is invalid\n";
exit(0);
}
if(siteoption == 1)
{
ques = "<p>";
ans = "text-viewer-wrapper\"";
quesloop = 1;
ansloop = 4;
}
if(siteoption == 2 || siteoption == 3)
{
ques = "title-tertiary\"";
ans = "answer answer-default\"";
quesloop = 1;
ansloop = 1;
}
if(siteoption == 4)
{
ques = "question_title\"";
ans = "answer noselect\"";
quesloop = 1;
ansloop = 1;
}
if(siteoption == 5)
{
ques = "<strong>";
ans = "type=\"radio\"";
quesloop = 1;
ansloop = 1;
}
if(siteoption == 6)
{
ques = "question-text\"";
ans = "opt_text\"";
quesloop = 1;
ansloop = 2;
}
if(siteoption == 7)
{
ques="qc-question-text\"";
ans="qc-answer-text\"";
quesloop = 1;
ansloop = 1;
}
if(siteoption == 8)
{
ques="wpvqgr-question-label\"";
ans="wpvqgr-answer-label\"";
quesloop=1;
ansloop=1;
}
if(siteoption == 9)
{
ques="snax-quiz-question-title\"";
ans="snax-quiz-answer-label-text\"";
quesloop=1;
ansloop=1;
}
if(siteoption == 10)
{
ques="question-title overlay\"";
ans="fa fa-check\"";
quesloop = 1;
ansloop = 3;
}
if(siteoption == 11)
{
ques="class=\"questions";
ans="class=\"answer\">";
quesloop = 8;
ansloop = 2;
}
if(siteoption == 12)
{
ques = "wdc_qc_caption_text\"";
ans = "wdc_qc_qtext\"";
quesloop = 1;
ansloop = 1;
}
pythonscript[dwiterator].open("pyparser.py");
string script = "from selenium import webdriver\nfrom selenium.webdriver.chrome.options import Options\noptions=Options()\nfrom time import sleep\nurl = \noptions.add_experimental_option( \"prefs\",{'profile.managed_default_content_settings.javascript': 2})\ndriver = webdriver.Chrome('C:/Users/USER/Desktop/chromedriver.exe', options=options)\ndriver.get(url)\nsleep(10)\nraw_html=driver.page_source\nfrom bs4 import BeautifulSoup as bs\nsoup = bs(raw_html,features='html.parser')\nprettyHTML = soup.prettify()\nopen('C:/Users/USER/Desktop/quiz.csv', 'w', encoding='utf-8')\nwith open('C:/Users/USER/Desktop/htmlparsing.txt', 'w', encoding='utf-8') as f:\n f.write(prettyHTML.replace('&', '&'))\n driver.quit()";
url.insert(0,"'");
url.append("'");
int findurl=script.find("url = ");
script.insert(findurl+6, url);
pythonscript[dwiterator]<<script;
pythonscript[dwiterator].close();
ShellExecuteA(NULL, "open", "pyparser.py", NULL, NULL, SW_SHOWNORMAL);
Sleep(40000);
html[dwiterator].open("htmlparsing.txt");
string line;
while(!html[dwiterator].eof())
{
line = "";
getline(html[dwiterator], line);
int y=0;
string x; x="";
int findques = 0;
findques = line.find(ques);
if(findques>0)
{
for(int i=1;i<=quesloop;i++)
{
line = "";
getline(html[dwiterator], line);
}
x=trim_spaces(line.c_str());
x.insert(0, "Q");
tempqa[qi] = x;
qi++;
y=1;
}
if(y==0)
{
int findans = 0;
findans = line.find(ans);
if(findans>0)
{
for(int i=1;i<=ansloop;i++)
{
line = "";
getline(html[dwiterator], line);
}
x=trim_spaces(line.c_str());
x.insert(0, "A");
tempqa[qi] = x;
qi++;
y=1;
}
}
}
html[dwiterator].close();
remove("pyparser.py");
remove("htmlparsing.txt");
Sleep(3000);
++dwiterator;
if(dwiterator<5)
{
cout<<"Do you want to continue? (Press 'Y' to continue and 'N' to exit)\n";
cin>>ch;
}
}
while(toupper(ch)!='N' && dwiterator<5);
int num_of_elements = sizeof(tempqa)/sizeof(tempqa[0]);
for(int i=0;i<num_of_elements;i++)
{
char ch,ch1;
ch = tempqa[i].c_str()[0];
if(i!=num_of_elements-1)
ch1 = tempqa[i+1].c_str()[0];
if(ch=='Q' && ch1=='Q')
{
for(int j=i;j<num_of_elements-1;j++)
{
tempqa[j]=tempqa[j+1];
}
}
}
ofstream allquestions;
allquestions.open("allquestions.txt");
for(int i=0;i<qi;i++)
{
char ch = tempqa[i].c_str()[0];
if(ch=='Q')
allquestions<<"Index of Question "<<i<<" "<<tempqa[i]<<"\n";
else
allquestions<<tempqa[i]<<"\n";
}
allquestions.close();
/*int allquestionsindex[15];
cout<<"Enter the index of all questions which you want to have:\n";
for(int i=0;i<15;i++)
cin>>allquestionsindex[i];*/
string mac[1000]; int y=0; int k=0;
for(int i=0;i<qi;i++)
{
char ch = tempqa[i].c_str()[0];
if(ch == 'Q' && k<15)
{
mac[y] = tempqa[i];
y++;
if(i<qi-1)
for(int j=i+1;tempqa[j].c_str()[0]=='A';j++)
{
mac[y]=tempqa[j];
y++;
}
k++;
}
}
int numofprsn;
char pd;
string dummy="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec fringilla placerat turpis eget imperdiet. Cras a dignissim tortor. Nunc et gravida nisi, et dignissim ex. Cras quis sem felis. Aenean ultricies finibus magna ut interdum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Aenean et.";
cout<<"How many personalities are there?\n";
cin>>numofprsn;
cout<<"Do you want to enter the personality Description? (Enter 'Y' for Yes and 'N' for No)\n";
cin>>pd;
for(int i=1;i<=numofprsn;i++)
{
cout<<"Enter the personality\n";
fflush(stdin);
getline(cin, res[ri]);
res[ri]=res[ri].insert(0,"#");
ri++;
if(toupper(pd) == 'Y')
{
cout<<"Enter the personality description\n";
fflush(stdin);
getline(cin, res[ri]);
}
else
{
fflush(stdin);
res[ri]=dummy;
}
ri++;
}
int pi=0;
for(int i=0;i<y;i++)
{
const char* th=mac[i].c_str();
if(th[0]=='A')
{
string x;
x=th;
x.append(res[pi]);
mac[i]=x;
pi=pi+2;
if(pi==ri)
pi=0;
}
}
cout<<"Enter the post ID of this quiz\n";
long int postid;
cin>>postid;
ofstream csv;
string qcsv = "quiz.csv";
qcsv.insert(0,to_string(postid));
rename("quiz.csv", qcsv.c_str());
csv.open(qcsv);
for(int i=0;i<y;i++)
{
const char* rt; const char* rt1;
rt=mac[i].c_str();
if(i!=y-1)
rt1=mac[i+1].c_str();
if(rt[0]=='Q')
{
csv<<"question"<<"*";
string x;
x=mac[i].substr(1,mac[i].size()-1);
csv<<x<<"*";
}
if(rt[0]=='A')
{
if(rt1[0]=='Q')
{
string x;
x=mac[i].substr(1,mac[i].size()-1);
csv<<x<<"*";
csv<<"\n";
}
else
{
string x;
x=mac[i].substr(1,mac[i].size()-1);
csv<<x<<"*";
}
}
}
csv<<"\n";
for(int i=0;i<ri;i++)
{
if(i%2==0 && i!=1)
{
csv<<"answer"<<"*";
string x;
x=res[i].substr(1,res[i].size()-1);
csv<<x<<"*";
}
else
{
//string x;
//x=res[i].substr(1,res[i].size()-1);
csv<<res[i]<<"\n";
}
}
csv.close();
return 0;
}
No comments:
Post a Comment