Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added loop to repeat update in python instead of OS. Added random-nes…
…s to the loop sleep time to make it seem more natural. Added multiple user-agents, update uses a random one each time. Added back off when given a captcha, eases back in on subsequent successes.
- Loading branch information
Showing
3 changed files
with
189 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,44 @@ | ||
import urllib.request, urllib.parse, urllib.error, urllib.request, urllib.error, urllib.parse, http.cookiejar | ||
import urllib.error | ||
import urllib.error | ||
import urllib.parse | ||
import urllib.parse | ||
import urllib.request | ||
import urllib.request | ||
from bs4 import BeautifulSoup | ||
from datetime import datetime | ||
import re | ||
|
||
class Page: | ||
fields = {} | ||
url = None | ||
connection = None | ||
html = None # BeautifulSoup object | ||
cookieJar = None | ||
opener = None | ||
response = None | ||
|
||
def __init__(self, url, cj): | ||
self.url = url | ||
self.cookieJar = cj | ||
|
||
def connect(self): | ||
print("---> Connecting to %s" % (self.url,)) | ||
|
||
self.opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(self.cookieJar)) | ||
self.opener.addheaders.append(('User-agent', 'Mozilla/4.0')) | ||
|
||
if self.fields: | ||
data = urllib.parse.urlencode(self.fields) | ||
binary_data = data.encode('ascii') | ||
self.response = self.opener.open(self.url, binary_data) | ||
print("-----> Sending data:") | ||
for c in list(self.fields.keys()): | ||
print("-------> %s = %s" % (c, self.fields[c][:20])) | ||
else: | ||
self.response = self.opener.open(self.url) | ||
|
||
self.html = BeautifulSoup(self.response.read(), "html.parser") | ||
|
||
# save the pages for diagnostic info | ||
# save = open(re.sub(r'\W+', '', self.html.title.string) + '.html', 'w') | ||
# save.write(str(self.html)) | ||
# save.close() | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
class Page: | ||
fields = {} | ||
url = None | ||
connection = None | ||
html = None # BeautifulSoup object | ||
cookieJar = None | ||
opener = None | ||
response = None | ||
|
||
def __init__(self, url, cj): | ||
self.url = url | ||
self.cookieJar = cj | ||
|
||
def connect(self, agent): | ||
print("---> Connecting to %s" % (self.url,)) | ||
|
||
self.opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(self.cookieJar)) | ||
self.opener.addheaders.append(('User-agent', agent)) | ||
|
||
if self.fields: | ||
data = urllib.parse.urlencode(self.fields) | ||
binary_data = data.encode('ascii') | ||
self.response = self.opener.open(self.url, binary_data) | ||
print("-----> Sending data:") | ||
for c in list(self.fields.keys()): | ||
print("-------> %s = %s" % (c, self.fields[c][:20])) | ||
else: | ||
self.response = self.opener.open(self.url) | ||
|
||
self.html = BeautifulSoup(self.response.read(), "html.parser") | ||
|
||
# save the pages for diagnostic info | ||
# save = open(re.sub(r'\W+', '', self.html.title.string) + '.html', 'w') | ||
# save.write(str(self.html)) | ||
# save.close() |
Oops, something went wrong.