我有一个列表,当我试图添加系统崩溃并显示以下错误时,我想使用python将多个项目附加到该列表中:
我已经尝试了append()
函数extend()
函数,但出现了相同的崩溃和错误
TypeError Traceback (most recent call last) <ipython-input-24-1e9480855366> in <module> 121 122 --> 123 joineddd.extend(link,jobdesc,alldd) 124 125 TypeError: extend() takes exactly one argument (3 given)
import time
import requests
from bs4 import BeautifulSoup
soup = BeautifulSoup(
requests.get("https://www.bayt.com/en/international/jobs/executive-chef-jobs/").content,
"lxml"
)
links = []
for a in soup.select("h2.m0.t-regular a"):
if a['href'] not in links:
links.append("https://www.bayt.com"+ a['href'])
joineddd = []
for link in links:
print(link)
s = BeautifulSoup(requests.get(link).content, "lxml")
jobdesc=s.select_one("div[class='card-content is-spaced'] p")
print(jobdesc.text)
alldt = [dt.text for dt in s.select("div[class='card-content is-spaced'] dt")]
dt_Job_location = alldt[0]
dt_Job_Company_Industry = alldt[1]
dt_Job_Company_Type = alldt[2]
if len(alldt[3])>0:
dt_Job_Job_Role = alldt[3]
elif len(dt_Job_Employment_Type)>0:
dt_Job_Employment_Type = alldt[4]
alldd = [dd.text for dd in s.select("div[class='card-content is-spaced'] dd")]
dd_job_location = alldd[0]
dd_job_Company_Industry = alldd[1]
dd_job_Company_Type = alldd[2]
if len(alldd[3])>0:
dd_job_Job_Role = alldd[3]
elif len(dd_job_Employment_Type)>0:
dd_job_Employment_Type = alldd[4]
print(f"{dt_Job_location}:{dd_job_location}\n{dt_Job_Company_Industry}:{dd_job_Company_Industry}\n\n")
print("-" * 80)
joineddd.extend(link,jobdesc,alldd)
预期结果:
[link,description,location,Company_Industry,Company_Type,Job_Role,Employment_Type ]
您可以使用
list.extend
方法,但在项目周围使用方括号,如下所示:数据帧:
输出:
对于扩展功能,您需要提供一个列表/touple/dict/set来添加多个项
例如:
相关问题 更多 >
编程相关推荐