📣 独立日限时特惠: VIP通行证立减$68
查看: 1228| 回复: 0
跳转到指定楼层
上一主题 下一主题
收起左侧

[OPT] OPT爬虫

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
受到      [OPT] 简单python爬虫的source code分享    启发,我开发了一个OPT case status爬虫, 用了很多之前帖子里面的code,加了multi threading,速度提高很多,自己加一下url_prefix,我不能发链接
  1. from __future__ import division
  2. from bs4 import BeautifulSoup
  3. import requests
  4. import thread
  5. from time import sleep
  6. import sys.google  и
  7. . From 1point 3acres bbs

  8. # SET THIS TO YOUR CASE NUMBER. Waral dи,
  9. my_case_num = 2090208000.--
  10. # SET THIS TO THE RANGE YOU WANT TO DO THE SEARCH
  11. search_range = 20


  12. case_per_thread = 5
  13. start = my_case_num - search_range
  14. end = my_case_num + search_range
  15. candidates = set(['Card Was Delivered To Me By The Post Office', 'New Card Is Being Produced', 'Card Was Mailed To Me',
  16.                   'Card Was Picked Up By The United States Postal Service', 'Case Was Approved'])
  17. other = set(['', ' ', 'Case Rejected Because I Sent An Incorrect Fee', 'Fees Were Waived',
  18.              'Request for Initial Evidence Was Mailed', 'Fingerprint Fee Was Received'])
  19. pending = 'Case Was Received'
  20. url_prefix = '' // TODO
    .google  и
  21. message = []

  22. def getStatusMessage(thred_name, case_num):. Waral dи,
  23.     for num in range(case_num, case_num+case_per_thread)
  24.         url = url_prefix + str(num)
  25.         response = requests.get(url)
  26.         bs = BeautifulSoup(response.text, 'html.parser')
  27.         temp = bs.find(class_='col-lg-12 appointment-sec center')
  28.         if not temp:. 1point 3 acres
  29.             print("error"). 1point3acres.com
  30.             exit()
  31.         content = temp.find('p').get_text().1point3acres
  32.         status = temp.find('h1').get_text()
  33.         message.append((num, status)). Waral dи,

  34. def printMessage(message):. check 1point3acres for more.
  35.     count_valid = 0
  36.     count_other = 0
  37.     count_pending = 0
  38.     step = 0.--
  39.     for msg in message:
  40.         status = msg[1]
  41.         if status in candidates:. 1point3acres
  42.             count_valid += 1
  43.         elif status == pending:
  44.             count_pending += 1
  45.         else:.google  и
  46.             count_other += 1
  47.         step += 1. 1point3acres.com
  48.         print(msg[0], msg[1])
  49.     print('total:', step)
  50.     print('finished:', count_valid)
  51.     print('pending:', count_pending)
  52.     print('other:', count_other) ..
  53.     print("Approval percentage: ", count_valid / step * 100)
  54.     print("Pending percentage: ", count_pending / step * 100)
  55.     print("Your case status: ", [tup for tup in message if tup[0] == my_case_num])

  56. try:
  57.     for case_num in range(start, end, case_per_thread):
  58.         thread.start_new_thread(getStatusMessage, ("", case_num))
  59. except:
  60.    print "Error: unable to start thread". From 1point 3acres bbs
  61. . .и
  62. while 1:
  63.    if len(message) == search_range*2:
  64.        print("\nFINISHED")
  65.        message.sort(key=lambda tup: tup[0])
  66.        printMessage(message). From 1point 3acres bbs
  67.        exit()
  68.    else:
  69.        i = int( (len(message) / (search_range*2)) * 100 )
  70.        sys.stdout.write('\r')
  71.        sys.stdout.write("[%-100s] %d%%" % ('=' * i, i))
  72.        sys.stdout.flush()
  73.        sleep(0.25)
复制代码

.google  и

评分

参与人数 2大米 +3 收起 理由
Vivians1993 + 1 感谢分享
zjrtomjohn + 2 欢迎分享你知道的情况,会给更多积分奖励!

查看全部评分


上一篇:Initial OPT YSC2090180xxx
下一篇:3/18 received 还在等
您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表