使用urllib无法在Google表中找到“下一步” 尝试使用标签:tbody,td和tr,但不知道如何解析内部标签。 代码如下:
def extracter(url,key,change):
if " " in key:
key=key.replace(" ",str(change))
url=url+str(key)
response=ur.Request(url,headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36'})
sauce =ur.urlopen(response).read()
soup=bs(sauce,"html.parser")
return soup
def google_next(key):
url = "https://www.google.com/search?q="
soup = extracter(url ,key,"+")
print(soup.findAll("a",{"class":"pnnext"}))
google("games")
输出:
response = meth(req, response)
File "C:\Users\loveislife\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 641, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Users\loveislife\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 569, in error
return self._call_chain(*args)
File "C:\Users\loveislife\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 503, in _call_chain
result = func(*args)
File "C:\Users\loveislife\AppData\Local\Programs\Python\Python37\lib\urllib\request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 429: Too Many Requests