|
本帖最后由 F1221880 于 2019-4-11 21:20 编辑
帮忙看一下,是哪里的问题?谢谢。
from bs4 import BeautifulSoup
import requests
import time
headers={
'User-Agent':'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Mobile Safari/537.36'
}
def judgment_**(class_name):
if class_name == ['member_icol']:
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")
titles = soup.select('div.pho_info>h4')
addresses = soup.select('span.pr5')
prices = soup.select('#pricePart>div.day_1>span')
imgs = soup.select('#floatRightBox>div.js_box.clearfix>div.member_pic>a>img')
names = soup.select('#floatRightBox>div.js_box.clearfix>div>h6>a')
**s = soup.select('#floatRightBox>div.js_box.clearfix>div.member_pic>div')
for title,address,price,img,name,** in zip(titles,addresses,prices,imgs,names,**s):
data ={
'title': title.get_text().strip(),
'address': address.get_text().strip(),
'price': price.get_text(),
'img' : img.get("src"),
'name' : name.get.text(),
'**' : judgment_**(**.get("class"))
}
print(data)
if __name__ == '__main__':
urls = ['http://sz.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)
运行结果只有:Process finished with exit code0code
|
|