爬虫要求验证,请问该如何处理?请赐教,不胜感激。
import urllib.request
import urllib.parse
from lxml import etree
import re
url = 'https://bke.bd.com/item/' + urllib.parse.quote('周杰伦')
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
}
req = urllib.request.Request(url=url, headers=headers, method='GET')
response = urllib.request.urlopen(req)
text = response.read().decode('utf-8')
print(text)
html = etree.HTML(text)
lt=[]
for i in range(1,6):
sen_list = html.xpath(f"/html/body/div[3]/div[2]/div/div[1]/div[4]/div[{i}]//text()")
l = [item.strip('\n') for item in sen_list]
l=''.join(l)
l=re.sub("\[+\d+\]","",l)
lt.append(l)
for i in range(len(lt)):
print(lt[i])
这种情况用梯子换ip能解决问题吗