pycharm 运行没有错误,可是却不运行处结果,是什么问题?
我不知道是哪里出了问题,我的代码从这地方开始就不显示结果了,请问是代码出了什么问题吗?还是需要用到debug?importpandasaspdimportnumpyasn...
我不知道是哪里出了问题,我的代码从这地方开始就不显示结果了,请问是代码出了什么问题吗?还是需要用到debug?import pandas as pdimport numpy as npimport timeimport seaborn as snsimport matplotlib.pyplot as pltfrom sklearn import preprocessingimport lightgbm aspip install pandas lgbfrom sklearn import log_lossimport mlx.warningswarnings.filterwarnings("ignore")train = pd.read_csv('D://天池大赛//train.csv', sep="\s+")train.shapetest_a= pd.read_csv('D://天池大赛//test_a.csv", sep="\s+")data = pd.concat([train, test_a])print(train)
展开
2个回答
展开全部
from bs4 import BeautifulSoup
import requests
import time
headers = {
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36'
}
def judgment_sex(class_name):
if class_name == ['member_ico1']:
return '女'
else:
return '男'
def get_links(url):
wb_data = requests.get(url,headers=headers)
soup = BeautifulSoup(wb_data.text,'lxml')
links = soup.select('#page_list > ul > li > a')
for link in links:
href = link.get("href")
get_info(href)
def get_info(url):
wb_data = requests.get(url,headers=headers)
soup = BeautifulSoup(wb_data.text,'lxml')
tittles = soup.select('div.pho_info > h4')
addresses = soup.select('span.pr5')
prices = soup.select('#pricePart > div.day_l > span')
imgs = soup.select('#floatRightBox > div.js_box.clearfix > div.member_pic > a > img')
names = soup.select('#floatRightBox > div.js_box.clearfix > div.w_240 > h6 > a')
sexs = soup.select('#floatRightBox > div.js_box.clearfix > div.member_pic > div')
for tittle, address, price, img, name, sex in zip(tittles,addresses,prices,imgs,names,sexs):
data = {
'tittle':tittle.get_text().strip(),
'address':address.get_text().strip(),
'price':price.get_text(),
'img':img.get("src"),
'name':name.get_text(),
'sex':judgment_sex(sex.get("class"))
}
print(data)
if __name__ == '__main__':
urls = ['http://bj.xiaozhu.com/search-duanzufang-p{}-0/'.format(number) for number in range(1,14)]
for single_url in urls:
get_links(single_url)
time.sleep(2)
我也遇到了这种情况,代码之前还能运行,突然就不行了,头疼
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询