Python 使用函数内部的函数,输入发生两次,需要一次
我试图从用户那里获得一次输入,然后打开这些链接。我尝试将第一个函数安装到第二个函数中,结果都成功了——但它两次要求我输入搜索项。我希望这件事发生一次。我如何纠正逻辑Python 使用函数内部的函数,输入发生两次,需要一次,python,urllib,Python,Urllib,我试图从用户那里获得一次输入,然后打开这些链接。我尝试将第一个函数安装到第二个函数中,结果都成功了——但它两次要求我输入搜索项。我希望这件事发生一次。我如何纠正逻辑 import urllib.request from bs4 import BeautifulSoup import re from collections import Counter import string from string import punctuation from collections import O
import urllib.request
from bs4 import BeautifulSoup
import re
from collections import Counter
import string
from string import punctuation
from collections import OrderedDict
from bs4.element import Comment
import pandas as pd
import requests
import re
import numpy as np
def user_input():
brand = input("search item?")
link1 = 'https://google.com/search?q='+brand+'&u=&'
link2 = 'http://yahoo.com/?site=thedrive&q='+brand
link3 = 'https://www.bloomberg.com/'+brand+'/news/'
link4 = 'https://www.cnet.com/roadshow/make/'+brand+'/'
list1 = [link1,link2,link3,link4]
return list1
def request():
html_list = []
list1 = user_input()
for item in list1:
with urllib.request.urlopen(item) as response:
html = response.read()
html_list.append(html)
return len(html_list)
user_input()
request()
您正在调用用户_input()两次。删除代码第二行到最后一行中的调用,您应该很好。标记为正确吗?