ฉันต้องการรวบรวมชุดสิทธิบัตรเกี่ยวกับคำค้นหา "รถยนต์" ฉันเขียนรหัสนี้:
import urllib2
from bs4 import BeautifulSoup
import sys
import StringIO
import re
search_term = 'automobile'
patent_list = []
for i in range(100): #for the first 100 pages of results
web_page = 'https://www.lens.org/lens/search?q=' + str(search_term) + '&sat=P&l=en&st=true&p=' + str(i) + '&n=100'
page = urllib2.urlopen(web_page)
soup = BeautifulSoup(page,'html.parser')
for aref in soup.findAll("a",href=True):
if re.findall('/lens/patent',aref['href']):
link = aref['href']
split_link = link.split('/')
if len(split_link) == 4:
patent_list.append(split_link[-1])
print '\n'.join(set(patent_list))
อย่างไรก็ตาม ฉันได้รับข้อผิดพลาด 503 ฉันค้นหาสิ่งนี้ใน Google และพบว่า: '
ขณะนี้เซิร์ฟเวอร์ไม่สามารถจัดการคำขอได้เนื่องจากการโอเวอร์โหลดชั่วคราวหรือการบำรุงรักษาเซิร์ฟเวอร์'
นี่หมายความว่า.
- อย่าใช้อัลกอริธึม ให้ประกอบ ID ด้วยตนเองแทน หรือ
- แบ่งคำขอออกเป็นชิ้นเล็กๆ
หากคำตอบคือ (2) ฉันจะแบ่งคำขอนี้เป็นคำขอเล็กๆ ได้อย่างไร