-
Notifications
You must be signed in to change notification settings - Fork 3
/
traffic_generator.py
206 lines (171 loc) · 4.96 KB
/
traffic_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# BY HycodeTech
from urllib.request import urlopen
from bs4 import BeautifulSoup
from urllib.request import HTTPError
import time
import re
import socket
import socks
from stem import Signal
from stem.control import Controller
import random
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
traffic="your website"
traffic_no=50
full_url_arr=set()
title_arr=set()
title_app=set()
page_app=set()
def blog_data(urlfile,page):
# prepare a cursor object using cursor() method
link="your website"
httplink=urlfile+page
print(httplink+" 00")
try:
ntraffic=0
scrap=0
rdnum=random.randint(40,300)
time.sleep(rdnum)
htmlfile=urlopen(httplink)
print(httplink+" 01")
htmltext=BeautifulSoup(htmlfile.read(),"lxml")
# print(httplink+" 02")
#url and text collection
rdtraffic=random.randint(1,3)
for sibling in htmltext.find_all("p","article_titile"):
inner_url=sibling.a['href']
# print(inner_url+" 1")
if inner_url:
title=""
# print(inner_url+" 2")
if inner_url:
# print(inner_url)
httplink=link+"/"+inner_url
if inner_url:
print(httplink+" 1")
# title=htmltext.p.previous_element
try:
rdnum=random.randint(50,300)
time.sleep(rdnum)
html_inner=urlopen(httplink)
print(httplink)
html_inner_text=BeautifulSoup(html_inner.read(),"lxml")
title=html_inner_text.find("div",class_="single_page_area").h1.text
rdnum=random.randint(50,300)
time.sleep(rdnum)
#selenium(httplink)
# time.sleep(10)
# sumary_arr.find('div').name='p'
# print(title)
ntraffic=ntraffic+1
print(ntraffic)
print(rdtraffic)
if ntraffic==rdtraffic:
break
except:
continue
# title=""
sumary=""
# for tit in title_arr:
# title=title+str(tit)
title=title.strip()
if len(title_app)==0:
title_app.add(title)
elif title in title_app:
title_app.add(title)
continue
nextPage=htmltext.find("li","nextPage").a['href']
nextPage="your website/index.php"+nextPage
if len(page_app)==0:
page_app.add(nextPage)
print(nextPage)
#blog_data(nextPage,"")
elif nextPage not in page_app:
page_app.add(nextPage)
print(nextPage)
#blog_data(nextPage,"")
else:
print("End of Page")
print("Start Another")
#db.close()
except HTTPError as he:
print(he)
# exit()
#continue
except AttributeError as ae:
print(ae)
# exit()
def anDch():
controller.signal(Signal.NEWNYM)
socks.set_default_proxy(socks.SOCKS5,"localhost",9150)
socket.socket=socks.socksocket
print(urlopen('http://icanhazip.com').read())
# htmlfile1=urlopen('https://whatismyipaddress.com/')
# htmltext1=BeautifulSoup(htmlfile1.read(),"lxml")
# print("0")
# for e in htmltext1.find_all('a'):
# lik=e.a['href']
# if "//whatismyipaddress.com/ip/" in lik:
# ipAdd=lik.split('/')
# ipAdd=ipAdd[len(ipAdd)-1]
# break
# print(ipAdd)
blog_data(traffic,"")
# for i in range(1,50):
try:
with Controller.from_port(port = 9151) as controller:
controller.authenticate()
for x in range(traffic_no):
anDch()
except:
print("error")
# continue
# blog_data(traffic,"")
def selenium(site):
service_args = [ '--proxy=localhost:9150', '--proxy-type=socks5', ]
driver = webdriver.PhantomJS(executable_path='C:/Python/work/phantomjs/bin/phantomjs',service_args=service_args)
driver.get(site)
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, "SC_TBlock_424845_Table")))
finally:
pageSource = driver.page_source
bsObj = BeautifulSoup(pageSource,"lxml")
#print(bsObj)
# bsObj.find("td","SC_TBlock_424845_Table")
for sibling in bsObj.find_all("td",class_="SC_TBlock_424845_td"):
#sibling.click()
print(sibling.table.tbody.tr.td.a['href'])
# exo=bsObj.find("noscript").a['href']
# print(exo)
a=[]
a=driver.find_elements_by_class_name("SC_TBlock_424845_td")
rdCLick=random.randint(0,3)
# for lt in a:
# lt.click()
rdclcSet=set()
for lt in range(rdCLick):
rdclc=random.randint(0,rdCLick)
if rdclc in rdclcSet:
continue
else:
rdclcSet.add(rdclc)
time.sleep(random.randint(40,100))
a[rdclc].click()
rdclcSet.clear()
count=0
while True:
count+=1
if count>20:
break
time.sleep(.5)
print("done")
# for lt in range(rdCLick):
# a[lt].click()
# driver.find_element_by_xpath("//table[@id='SC_TBlock_424845_Table']/tbody/tr/td/table/tbody/tr/td/a").text
#driver.find_element_by_xpath("//td[@class='SC_TBlock_424845_td']/table/tbody/tr/td/a").text
driver.close()