注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
受到 [OPT] 简单python爬虫的source code分享 启发,我开发了一个OPT case status爬虫, 用了很多之前帖子里面的code,加了multi threading,速度提高很多,自己加一下url_prefix,我不能发链接
- from __future__ import division
- from bs4 import BeautifulSoup
- import requests
- import thread
- from time import sleep
- import sys.google и
- . From 1point 3acres bbs
- # SET THIS TO YOUR CASE NUMBER. Waral dи,
- my_case_num = 2090208000.--
- # SET THIS TO THE RANGE YOU WANT TO DO THE SEARCH
- search_range = 20
- case_per_thread = 5
- start = my_case_num - search_range
- end = my_case_num + search_range
- candidates = set(['Card Was Delivered To Me By The Post Office', 'New Card Is Being Produced', 'Card Was Mailed To Me',
- 'Card Was Picked Up By The United States Postal Service', 'Case Was Approved'])
- other = set(['', ' ', 'Case Rejected Because I Sent An Incorrect Fee', 'Fees Were Waived',
- 'Request for Initial Evidence Was Mailed', 'Fingerprint Fee Was Received'])
- pending = 'Case Was Received'
- url_prefix = '' // TODO
.google и - message = []
- def getStatusMessage(thred_name, case_num):. Waral dи,
- for num in range(case_num, case_num+case_per_thread)
- url = url_prefix + str(num)
- response = requests.get(url)
- bs = BeautifulSoup(response.text, 'html.parser')
- temp = bs.find(class_='col-lg-12 appointment-sec center')
- if not temp:. 1point 3 acres
- print("error"). 1point3acres.com
- exit()
- content = temp.find('p').get_text().1point3acres
- status = temp.find('h1').get_text()
- message.append((num, status)). Waral dи,
- def printMessage(message):. check 1point3acres for more.
- count_valid = 0
- count_other = 0
- count_pending = 0
- step = 0.--
- for msg in message:
- status = msg[1]
- if status in candidates:. 1point3acres
- count_valid += 1
- elif status == pending:
- count_pending += 1
- else:.google и
- count_other += 1
- step += 1. 1point3acres.com
- print(msg[0], msg[1])
- print('total:', step)
- print('finished:', count_valid)
- print('pending:', count_pending)
- print('other:', count_other) ..
- print("Approval percentage: ", count_valid / step * 100)
- print("Pending percentage: ", count_pending / step * 100)
- print("Your case status: ", [tup for tup in message if tup[0] == my_case_num])
- try:
- for case_num in range(start, end, case_per_thread):
- thread.start_new_thread(getStatusMessage, ("", case_num))
- except:
- print "Error: unable to start thread". From 1point 3acres bbs
- . .и
- while 1:
- if len(message) == search_range*2:
- print("\nFINISHED")
- message.sort(key=lambda tup: tup[0])
- printMessage(message). From 1point 3acres bbs
- exit()
- else:
- i = int( (len(message) / (search_range*2)) * 100 )
- sys.stdout.write('\r')
- sys.stdout.write("[%-100s] %d%%" % ('=' * i, i))
- sys.stdout.flush()
- sleep(0.25)
复制代码
.google и
|