鱼C论坛

 找回密码
 立即注册
查看: 942|回复: 1

[已解决]sos 我这哪里错误 求解答,怎么显示不出我想要的结果

[复制链接]
发表于 2020-8-8 20:24:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
import requests
from bs4 import BeautifulSoup
import re
import time
import openpyxl


def open_url(url):
    headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0'}

    res = requests.get(url, headers=headers, timeout=500)
    return res

def main():

    host = "https://www.ebay.com.au/itm/264257008562"
    res = open_url(host)
    soup = BeautifulSoup(res.text, "html.parser")
    for info in soup.find_all('select',class_="msku-sel "):
        result = info.text
        print(info["id"])


if __name__ == "__main__":
    main()
    print("已完成")


最佳答案
2020-8-8 23:01:31

class_="msku-sel " 去掉最后的一个空格即可:
import requests
from bs4 import BeautifulSoup
import re
import time
import openpyxl


def open_url(url):
    headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0'}

    res = requests.get(url, headers=headers, timeout=500)
    return res

def main():

    host = "https://www.ebay.com.au/itm/264257008562"
    res = open_url(host)
    soup = BeautifulSoup(res.text, "html.parser")
    for info in soup.find_all('select',class_="msku-sel"):
        result = info.text
        print(info["id"])


if __name__ == "__main__":
    main()
    print("已完成")
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-8-8 23:01:31 | 显示全部楼层    本楼为最佳答案   

class_="msku-sel " 去掉最后的一个空格即可:
import requests
from bs4 import BeautifulSoup
import re
import time
import openpyxl


def open_url(url):
    headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0'}

    res = requests.get(url, headers=headers, timeout=500)
    return res

def main():

    host = "https://www.ebay.com.au/itm/264257008562"
    res = open_url(host)
    soup = BeautifulSoup(res.text, "html.parser")
    for info in soup.find_all('select',class_="msku-sel"):
        result = info.text
        print(info["id"])


if __name__ == "__main__":
    main()
    print("已完成")
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-19 14:09

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表