import requests from bs4 import BeautifulSoup import re from urllib import request
header={'Referer':'https://www.qidian.com/xuanhuan', 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36 LBBROWSER'}
def Getinfo(url):
response = requests.get(url,headers=header)
response2= request.urlopen(url,timeout=10)
soup =BeautifulSoup(response.text,'lxml')
a = re.compile('</a></td><td><a class="name" .*?>(.*?)</a>')
b = re.findall(a,response2.read().decode('utf-8'))
for i in soup.find_all('div', class_="update-table all"): for j in i.find_all(class_='name'):
src =j.get('href')
src2='http:'+src #到这边打印的src2正常获取到
response3 =requests.get(src2)
soup2=BeautifulSoup(response3.text,'lxml')
print(soup2) url='https://www.qidian.com/xuanhuan'