sos 我这哪里错误 求解答,怎么显示不出我想要的结果
import requestsfrom 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("已完成")
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("已完成")
页:
[1]