함수에 전달할 수있는 문자열 안에 키워드가있는 매개 변수 목록을 사용할 수 있는지 알고 싶습니다. 기본적으로 매개 변수 목록에는 키워드가 있거나 없을 수 있으므로 매개 변수 목록에는 '유형'변수가 있습니다. 당신은 키워드 인수 사전에 토큰 목록을 분할해야변수 유형이있는 매개 변수 목록 Python 3?
from bs4 import BeautifulSoup
import urllib.request as urlreq
import my_parameters # can have variable values
# my_parameters.useful_token_concept = ["h1", "class_ = some_class"]
# I want to pass these above parameters into a function; "class_" is
# a keyword, but it's wrapped in a string => gives me problems
url = my_parameters.url
page = urlreq.urlope(url)
pageHtml = page.read()
page.close()
soup = BeautifulSoup(pageHtml)
# something like the following line works:
# params = soup.find("h1", class_ = "some_class")
params = soup.find(*my_parameters.useful_token_concept)
# params = soup.find(my_parameters.useful_token_concept[0],\
# my_parameters.useful_token_concept[1])
# I don't know how long the list of attributes/parameter-list to
# BeautifulSoup's find() function will be, nor do I know what keywords,
# if any, will be passed into find(), as given by a user to my_parameters.
print(params) # should print the html the user wants to scrape.