python 爬虫报错 , 是什么原因呢?
importrequestsfrombs4importBeautifulSoupimporttimeheaders={'User-Agent':'Mozilla/5.0(...
import requests
from bs4 import BeautifulSoup
import time
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'}
def get_info():
wb_data = requests.get('http://www.kugou.com/yy/rank/home/1-8888.html', headers = headers)
soup = BeautifulSoup(wb_data.text, 'lxml')
ranks = soup.select('span.pc_temp_num')
times = soup.select('span.pc_temp_tips_r > span')
for rank,time in zip( ranks, times):
data = {'rank': rank.get_text().strip(), 'time': time.get_text().strip()}
print(data)
get_info() 展开
from bs4 import BeautifulSoup
import time
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'}
def get_info():
wb_data = requests.get('http://www.kugou.com/yy/rank/home/1-8888.html', headers = headers)
soup = BeautifulSoup(wb_data.text, 'lxml')
ranks = soup.select('span.pc_temp_num')
times = soup.select('span.pc_temp_tips_r > span')
for rank,time in zip( ranks, times):
data = {'rank': rank.get_text().strip(), 'time': time.get_text().strip()}
print(data)
get_info() 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询