本文整理汇总了Python中mechanize.Browser.geturl方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.geturl方法的具体用法?Python Browser.geturl怎么用?Python Browser.geturl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mechanize.Browser
的用法示例。
在下文中一共展示了Browser.geturl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _process
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import geturl [as 别名]
def _process(self):
"""Start the work."""
movie = '+'.join(self.title.split())
br = Browser()
url = "%s/find?s=tt&q=%s" % (self.BASE_URL, movie)
br.open(url)
if re.search(r'/title/tt.*', br.geturl()):
self.url = "%s://%s%s" % urlparse.urlparse(br.geturl())[:3]
soup = BeautifulSoup( MyOpener().open(url).read() )
else:
link = br.find_link(url_regex = re.compile(r'/title/tt.*'))
res = br.follow_link(link)
self.url = urlparse.urljoin(self.BASE_URL, link.url)
soup = BeautifulSoup(res.read())
try:
self.title = soup.find('h1').contents[0].strip()
for span in soup.findAll('span'):
if span.has_key('itemprop') and span['itemprop'] == 'ratingValue':
self.rating = span.contents[0]
break
self.found = True
except:
pass
示例2: _process
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import geturl [as 别名]
def _process(self):
"""Start the work."""
movie = "+".join(self.title.split())
br = Browser()
url = "%s/find?s=tt&q=%s" % (self.BASE_URL, movie)
br.open(url)
if re.search(r"/title/tt.*", br.geturl()):
self.url = "%s://%s%s" % urlparse.urlparse(br.geturl())[:3]
soup = BeautifulSoup(MyOpener().open(url).read(), "html.parser")
else:
link = br.find_link(url_regex=re.compile(r"/title/tt.*"))
res = br.follow_link(link)
self.url = urlparse.urljoin(self.BASE_URL, link.url)
soup = BeautifulSoup(res.read(), "html.parser")
try:
self.title = soup.find("h1").contents[0].strip()
for span in soup.findAll("span"):
if span.has_attr("itemprop") and span["itemprop"] == "ratingValue":
self.rating = span.contents[0]
break
self.found = True
except:
pass
self.genre = []
infobar = soup.find("div", {"class": "infobar"})
r = infobar.find("", {"title": True})["title"]
self.genrelist = infobar.findAll("a", {"href": True})
for i in range(len(self.genrelist) - 1):
self.genrelist[i] = self.genrelist[i].encode("ascii")
self.genre.append(self.genrelist[i][16 : self.genrelist[i].index("?")])
self.mainGenre = self.genre[0]
示例3: check
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import geturl [as 别名]
def check(acs):
for a in acs:
try:
a = a.rsplit()[0]
except:
pass
try:
if a:
a = a.split(':')
user = a[0]
passw = a[1]
br = Browser()
br.set_handle_gzip(True)
br.set_handle_robots(False)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
br.open('http://m.facebook.com/login.php')
br.select_form(nr=0)
br.form['email'] = user
br.form['pass'] = passw
br.submit()
if 'm.facebook.com/login.php' in br.geturl() or 'checkpoint' in br.geturl() or 'to confirm your account with Facebook.' in br.response().read():
print "Could not login with " + str(a)
else:
print "Logged in with " + user
opn = open(newfile, 'a')
opn.write(user + ":" + passw + '\n')
opn.close()
except:
print "Could not login with " + str(a)
示例4: login_and_authorize
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import geturl [as 别名]
def login_and_authorize(authorize_url, config):
print "AUTHORIZING", authorize_url
br = Browser()
br.set_debug_redirects(True)
br.open(authorize_url)
print "FIRST PAGE", br.title(), br.geturl()
br.select_form(nr=1)
br['login_email'] = config['testing_user']
br['login_password'] = config['testing_password']
resp = br.submit()
print "RESULT PAGE TITLE", br.title()
print "RESULT URL", resp.geturl()
assert br.viewing_html(), "Looks like it busted."
try:
br.select_form(nr=1)
br.submit()
br.viewing_html(), "Looks like it busted."
assert "API Request Authorized" in br.title(), "Title Is Wrong (bad email/password?): %r at %r" % (br.title(), br.geturl())
except FormNotFoundError:
print "Looks like we're blessed."
示例5: BachBrowser
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import geturl [as 别名]
class BachBrowser(object):
def __init__(self):
self._b = Browser()
def login(self, user, pin):
# submit login form
login_data = urlencode({'yzbks': user, 'jklwd': pin})
self._b.open(servlet_url('SSOLogin'), login_data)
# open the content frame
self._b.follow_link(name='content')
# ack the "please don't forget to logout" form (if present)
try:
self._b.select_form('Main')
self._b.submit()
except FormNotFoundError:
pass
# store current session id
self._b.select_form('Main')
self._session_id = self._b['sessionid']
# store the url of the "overview" page
self._root_url = self._b.geturl()
def logout(self):
try:
self._b.open(servlet_url('Logout'))
except HTTPError, e:
if e.code != 503:
raise e
示例6: getRatings
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import geturl [as 别名]
def getRatings(url):
# url = 'http://us.imdb.com/M/title-exact?Moighty%20Aphrodite%20(1995)'
try:
br = Browser()
br.set_handle_robots(False)
br.open(url)
if re.search(r'/title/tt.*', br.geturl()):
soup = BeautifulSoup(MyOpener().open(url).read())
else:
link = br.find_link(url_regex = re.compile(r'/title/tt.*'))
res = br.follow_link(link)
soup = BeautifulSoup(res.read())
# movie_title = soup.find('title').contents[0]
des = (soup.find('meta',{'name':'description'})['content']).encode('utf-8')
rate = soup.find('span',itemprop='ratingValue')
# print movie_title
# print des
except:
print 'Error no rating'
rating = str(0)
des = ""
else:
if rate:
rating = str(rate.contents[0])
else:
rating = str(0)
print 'No rate'
return rating, des
示例7: get_browser
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import geturl [as 别名]
def get_browser(self):
"""
Each FAUrl object stores it's own browser instance. On the first call
it is created and if the username and password is set it will
authenticate you.
:return: mechanize.Browser instance.
:raise: FAiler.FAError if FA is down. Time to F5!
:raise: FAiler.FAAuth Your username and password failed
"""
if self._br is None:
br = Browser()
br.set_handle_robots(False)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_equiv(True)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
if self._username is not None and self._password is not None:
loginPage = 'https://www.furaffinity.net/login'
try:
br.open(loginPage)
except urllib2.HTTPError:
raise FAError("FA's down, F5 time.")
br.form = br.global_form()
br.form['name'] = self._username
br.form['pass'] = self._password
br.form.method = 'POST'
br.submit()
if br.geturl() == loginPage + '/?msg=1':
raise FAAuth('Username & Password Incorrect')
self._br = br
return self._br
示例8: login_and_authorize
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import geturl [as 别名]
def login_and_authorize(argv=None):
if argv is None:
argv = sys.argv
authorize_url = argv[1]
config = json.loads(argv[2])
print "AUTHORIZING", authorize_url
br = Browser()
br.set_debug_redirects(True)
br.open(authorize_url)
print "FIRST PAGE", br.title(), br.geturl()
br.select_form(nr=2)
br["login_email"] = config[u"testing_user"]
br["login_password"] = config[u"testing_password"]
resp = br.submit()
print "RESULT PAGE TITLE", br.title()
print "RESULT URL", resp.geturl()
assert br.viewing_html(), "Looks like it busted."
try:
br.select_form(nr=2)
br.submit()
assert br.viewing_html(), "Looks like it busted."
assert "API Request Authorized" in br.title(), "Title Is Wrong (bad email/password?): %r at %r" % (br.title(), br.geturl())
except FormNotFoundError:
print "Looks like we're blessed."
return "OK"
示例9: _process
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import geturl [as 别名]
def _process(self):
movie = '+'.join(self.title.split())
br = Browser()
url = "%s/find?s=tt&q=%s" % (self.BASE_URL, movie)
br.open(url)
if re.search(r'/title/tt.*', br.geturl()):
self.url = "%s://%s%s" % urlparse.urlparse(br.geturl())[:3]
soup = BeautifulSoup( MyOpener().open(url).read() )
else:
link = br.find_link(url_regex = re.compile(r'/title/tt.*'))
res = br.follow_link(link)
self.url = urlparse.urljoin(self.BASE_URL, link.url)
soup = BeautifulSoup(res.read())
try:
self.title = soup.find('h1').contents[0].strip()
self.rating = soup.find('span',attrs='rating-rating').contents[0]
self.found = True
except:
pass
示例10: testWebDip
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import geturl [as 别名]
def testWebDip():
br = Browser()
br.open("http://webdiplomacy.net/logon.php")
br.select_form(nr=0)
br['loginuser'] = "USERNAMEHERE"
br['loginpass'] = "PASSWORDHERE"
br.submit()
br.open("http://webdiplomacy.net/index.php")
resp = br.reload()
html = resp.read()
soup = BeautifulSoup("".join(html))
notices = soup.find("div", {"class": "gamelistings-tabs"})
if notices is None:
return
elif notices.find("img", {"src": "images/icons/alert.png"}):
webbrowser.open(br.geturl())
print "It's your turn in WebDiplomacy"
print ""
elif notices.find("img", {"src": "images/icons/mail.png"}):
webbrowser.open(br.geturl())
print "You have mail in WebDiplomacy"
print ""
示例11: _process
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import geturl [as 别名]
def _process(self):
"""Start the work."""
movie = '+'.join(self.title.split())
br = Browser()
url = "%s/find?s=tt&q=%s" % (self.BASE_URL, movie)
br.open(url)
if re.search(r'/title/tt.*', br.geturl()):
self.url = "%s://%s%s" % urlparse.urlparse(br.geturl())[:3]
soup = BeautifulSoup( MyOpener().open(url).read() )
else:
link = br.find_link(url_regex = re.compile(r'/title/tt.*'))
res = br.follow_link(link)
self.url = urlparse.urljoin(self.BASE_URL, link.url)
soup = BeautifulSoup(res.read())
try:
self.title = soup.find('h1').contents[0].strip()
for span in soup.findAll('span'):
if span.has_key('itemprop') and span['itemprop'] == 'ratingValue':
self.rating = span.contents[0]
break
self.found = True
except:
pass
# class ImdbRating
# if __name__ == "__main__":
# if len(sys.argv) == 1:
# print "Usage: %s 'Movie title'" % (sys.argv[0])
# else:
# imdb = ImdbRating(sys.argv[1])
# if imdb.found:
# print imdb.url
# print imdb.title
# print imdb.rating
示例12: __init__
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import geturl [as 别名]
class Api:
appid = '5415093'
token = None
query_pattern = 'https://api.vk.com/method/%s?%s&access_token='
ua = 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1'
br = None
cl = None
def __init__(self, login, password, scope, testmode=False):
self.br = Browser()
self.cl = cookielib.LWPCookieJar()
self.br.set_cookiejar(self.cl)
self.br.set_handle_equiv(True)
self.br.set_handle_redirect(True)
self.br.set_handle_referer(True)
self.br.set_handle_robots(False)
self.br.set_handle_refresh(_http.HTTPRefreshProcessor(), max_time=1)
self.br.addheaders = [('User-agent', self.ua)]
self.br.open('https://oauth.vk.com/authorize?client_id=' + self.appid +
'&scope=' + scope + '&redirect_uri=http://oauth.vk.com/blank.html' +
'&display=mobile&response_type=token')
self.br.select_form(nr=0)
self.br.form['email'] = login
self.br.form['pass'] = password
self.br.submit()
if len(list(self.br.forms())) > 0:
self.br.select_form(nr=0)
self.br.submit()
params = urlparse.urlparse(self.br.geturl()).fragment
params = params.split('&')
for val in params:
tp = val.split('=')
if tp[0] == 'access_token':
self.token = tp[1]
self.query_pattern += self.token
if testmode:
self.query_pattern += '&test_mode=1'
break
def query(self, func, data):
response = self.br.open(self.query_pattern % (func, data))
return response.read()
示例13: get_product_url
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import geturl [as 别名]
def get_product_url(item_list):
"""
Return the url for each item in item_list from flipkart.
"""
url_list = []
br = Browser() #get the browser instance
br.set_handle_robots(False) #ignore robot.txt
br.addheaders = [('User-agent', 'Firefox')] # setting browser agent
br.open("http://www.flipkart.com/") # open url
for item in item_list:
br.select_form(nr=1) #select form using postion, as form name is nor available
br.form['q'] = item # set item to be searched
br.submit()
url_list.append(br.geturl())
return url_list
示例14: Scraper
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import geturl [as 别名]
class Scraper(object):
def __init__(self):
self.b = Browser()
self.b.set_handle_robots(False)
self.appkey = None
self.GetAppKey()
def GetAppKey(self):
self.b.open("http://www.vancouversun.com/parking/basic-search.html")
html = self.b.response().read()
soup = BeautifulSoup(html)
for div in soup.findAll('div'):
if div.has_key('id') and div['id'] == 'cxkg':
self.appkey = div.findAll('a')[0]['href'].split('AppKey=')[1].split('&')[0]
logging.info('Got app key=%s', self.appkey)
break
def ScrapeTickets(self, page):
assert len(self.appkey) > 10
url = ENDPOINT % (self.appkey, page)
logging.debug('Opening url: %s', url)
startTime = time.time()
self.b.open(url)
logging.info('Loaded page in %d seconds', time.time() - startTime)
logging.info('Starting to scrape tickets from page %d', page)
doc = HTML.fromstring(self.b.response().read(), self.b.geturl())
tickets = []
fields = ["date", "Time", "plate", "make", "street_num", "street_name", "offence", "record_id"]
for tr in doc.xpath("//table[1]/tr[@class='cbResultSetEvenRow'] | //table[1]/tr[@class='cbResultSetOddRow']"):
values = [td.text for td in tr.getchildren()[:7]]
td_details=tr.getchildren()[7]
# get the RecordID
values.append(re.search(recordID_regexp, td_details.xpath("a/@href")[0]).group(1))
ticket = Ticket(zip(fields, values))
ticket.CleanUpRawTicket()
tickets.append(ticket)
logging.info('Finished scraping %d tickets from page %d', len(tickets), page)
return tickets
示例15: main
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import geturl [as 别名]
def main():
cj = cookielib.LWPCookieJar('cookie.txt')
try:
cj.load('cookie.txt')
except IOError:
print "Кукисы не найдены"
root_url = 'http://188.134.114.45/store1/admin/'
admin_url ='http://188.134.114.45/store1/admin/index.php?route=common/home&token='
suppler_url = "http://188.134.114.45/store1/admin/index.php?route=catalog/suppler/update&token="
orinon1_url = '&suppler_id=1'
orinon2_url = '&suppler_id=2'
username = 'admin'
userpass = '1q2w'
br = Browser()
br.set_handle_robots(False)
br.set_cookiejar(cj)
br.addheaders = [('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.6')]
home_page = br.open(root_url)
print br.title()
br.select_form(nr=0)
br["username"] = username
br["password"] = userpass
br.submit()
token = getToken(br.geturl())
cj.save('cookie.txt')
br.open(suppler_url + token + orinon1_url)
br.select_form(nr = 1)
control = br.form.find_control("command")
control.set_value_by_label(("Удалить товары",))
res = br.submit()
br.open(suppler_url + token + orinon2_url)
br.select_form(nr = 1)
control = br.form.find_control("command")
control.set_value_by_label(("Удалить товары",))
res = br.submit()