无味33 2021-10-18 19:37 采纳率: 63.3%
浏览 28
已结题

运行框中没有爬出来的数据

!pip install openpyxl
import requests
from bs4 import BeautifulSoup
from openpyxl import Workbook
def get_search_list(keyword=None,page=1):
    url ='http://www.mailiangwang.com/biz/list'
    payload ={'keyword':keyword, 'pageid':page}
    response = requests.get(url,params=payload)
    print(response.url)
    print(response.status_code)
get_search_list(u'玉米',1)
name_total = []
caption_total = []
addr_total = []
category_total = []
def get_search_list(keyword=None,page=1):
    url ='http://www.mailiangwang.com/biz/list'
    payload ={'keyword':keyword, 'pageid':page}
    response = requests.get(url,params=payload)
    soup = BeautifulSoup(response.text,'lxml')
    links = soup.select('body>div.wrap >div.merchantList >div.p_dataList >div.p_dataItem >span.n1 >a')
    captions = soup.select('body > div.wrap > divmerchanList > div.p_dataList > div.p_dataIlem > span.n4')
    addrs = soup.select('body > div.wrap >div.merchanList >div.p_dataList >div.p_dataItem > span.n5')
    categories = soup.select('body > div.wrap >div.merchantList >div.p_dataItem >span.n6')
    for link,caption,addr,category in zip(links, captions, addrs, categories):
        name_total.append(link.get('title').strip())
        caption_total.append(caption.text)
        addr_total.append(addr.text)
        category_total.append(category.text)
get_search_list('玉米',1)
print(name_total)
print(caption_total)

  • 写回答

1条回答 默认 最新

  • 无味33 2021-10-18 20:52
    关注
    !pip install openpyxl
    import requests
    from bs4 import BeautifulSoup
    from openpyxl import Workbook
    def get_search_list(keyword=None,page=1):
        url ='http://www.mailiangwang.com/biz/list'
        payload ={'keyword':keyword, 'pageid':page}
        response = requests.get(url,params=payload)
        print(response.url)
        print(response.status_code)
    get_search_list(u'玉米',1)
    name_total = []
    caption_total = []
    addr_total = []
    category_total = []
    def get_search_list(keyword=None,page=1):
        url ='http://www.mailiangwang.com/biz/list'
        payload ={'keyword':keyword, 'pageid':page}
        response = requests.get(url,params=payload)
        soup = BeautifulSoup(response.text,'lxml')
        links = soup.select('body>div.wrap >div.merchantList >div.p_dataList >div.p_dataItem >span.n1 >a')
    captions = soup.select('body > div.wrap > div.merchantList > div.p_dataList > div.p_dataItem > span.n4')
        addrs = soup.select('body > div.wrap > div.merchantList >div.p_dataList >div.p_dataItem > span.n5')
        categories = soup.select('body > div.wrap > div.merchantList >div.p_dataList >div.p_dataItem >span.n6')
        for link,caption,addr,category in zip(links, captions, addrs, categories):
            name_total.append(link.get('title').strip())
            caption_total.append(caption.text)
            addr_total.append(addr.text)
            category_total.append(category.text)
    get_search_list('玉米',1)
    print(name_total)
    print(caption_total)
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月26日
  • 已采纳回答 10月18日
  • 创建了问题 10月18日

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向