小白求教!!!

为什么我这段代码在Juptyer上运行不出结果,但也没有显示什么错误,求教!

from lxml import etree
import requests
import csv
import time

if name ==‘main’:
headers={
‘User-Agent’: ‘Mozilla/5.0 (Windows NT 10.0; WOW64)AppleWebkit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80Safari/537.36’}

start_url= ‘https://esf.fang.com/house/i’
for x in range(32,35):
url = start_url + str(x)
html = requests.get(url,headers = headers)
time.sleep(1)
selector = etree.HTML(html.text)
xiaoqulist = selector.xpath(’//*[@id=“kesfqbfylb_A01_01”]’)
for xiaoqu in xiaoqulist:
mingcheng = xiaoqu.xpath(‘dd[1]/h4/a/span/text()’)[0]
bankuai = xiaoqu.xpath(‘dd[1]/p[2]/a/text()’)[0]
junjia = xiaoqu.xpath(‘dd[2]/span[2]text()’)[0]
item = [mingcheng,bankuai,junjia]
writecsv(item)
print(‘正在抓取:’,mingcheng)

def writecsv(item):
with open(‘hhhh.csv’,‘wt’,encoding = ‘utf-8’) as f:
writer = csv.writer(f)
try:
writer.writerow(item)
except:
print(‘write error!’)

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值