我在 Python 中打印列表时遇到问题
I have a problem with printing a list in Python
我的代码是:
import json
with open(r'C:\Users\kevin\Dropbox\webcrawler\webcrawler\webcrawler\jobscout24.json') as f:
data = json.load(f)
values = ','.join([str(i) for i in data])
my_list = values.split(",")
my_list = values.split("'")
links = [my_list]
for i in my_list:
a = 'https://www.jobscout24.ch' + i
print (a)
!我的输出:(https://i.stack.imgur.com/dB4tS.png)
输出应该只是带有数字的链接(即(https://www.jobscout24.ch/de/job/senior-systems-engineer-citrix/7139368/)
它不应该包含没有数字的链接(即(https://www.jobscout24.ch)
我已经尝试使用以下方法仅提取每个第二个元素:
print (a[::2])
但这并没有像预期的那样工作。
json 文件的内容:[ {"datajoburltext": ["/de/job/system-engineer-global-infrastructure/7184973/", "/de/job/systems-engineer/7141131/", "/de/job/systems-engineer-digital-workplace-consultant/7138024/", "/de/job/systems-engineer-vmware-consultant/7138051/", "/de/job/systems-engineer-voice-enterprise-mobility/7188224/", "/de/job/systems-engineer-100/7020537/", "/de/job/systems-engineer-diabetes-care/7214185/", "/de/job/level-end-user-systems-engineer/7156570/", "/de/job/systems-engineer-workplace/7141116/", "/de/job/systems-engineer/7194974/", "/de/job/systems-engineer/7194972/", "/de/job/senior-systems-engineer-citrix/7139368/", "/de/job/information-systems-engineer/7154423/", "/de/job/windows-systems-engineer/7179959/", "/de/job/systems-engineer-ecm/7169846/", "/de/job/systems-engineer-operations/7165522/", "/de/job/praktikant-systems-engineer-jet/7192042/", "/de/job/systems-engineer/7219016/", "/de/job/systems-engineer-client-und-mobile-management/7197563/", "/de/job/solution-architect-vmware-consultant/7141122/", "/de/job/systems-engineer-diabetes-care/7214185/", "/de/job/senior-systems-engineer-citrix/7139368/"]} ]
希望你能帮助我。
您必须与 json-object 一起工作。但不是字符串。
import json
with open(r'C:\Users\kevin\Dropbox\webcrawler\webcrawler\webcrawler\jobscout24.json') as f:
data = json.load(f)
url_parts = sum((p["datajoburltext"] for p in data), [])
print(*['https://www.jobscout24.ch' + part for part in url_parts], sep='\n')
我的代码是:
import json
with open(r'C:\Users\kevin\Dropbox\webcrawler\webcrawler\webcrawler\jobscout24.json') as f:
data = json.load(f)
values = ','.join([str(i) for i in data])
my_list = values.split(",")
my_list = values.split("'")
links = [my_list]
for i in my_list:
a = 'https://www.jobscout24.ch' + i
print (a)
!我的输出:(https://i.stack.imgur.com/dB4tS.png)
输出应该只是带有数字的链接(即(https://www.jobscout24.ch/de/job/senior-systems-engineer-citrix/7139368/)
它不应该包含没有数字的链接(即(https://www.jobscout24.ch)
我已经尝试使用以下方法仅提取每个第二个元素:
print (a[::2])
但这并没有像预期的那样工作。
json 文件的内容:[ {"datajoburltext": ["/de/job/system-engineer-global-infrastructure/7184973/", "/de/job/systems-engineer/7141131/", "/de/job/systems-engineer-digital-workplace-consultant/7138024/", "/de/job/systems-engineer-vmware-consultant/7138051/", "/de/job/systems-engineer-voice-enterprise-mobility/7188224/", "/de/job/systems-engineer-100/7020537/", "/de/job/systems-engineer-diabetes-care/7214185/", "/de/job/level-end-user-systems-engineer/7156570/", "/de/job/systems-engineer-workplace/7141116/", "/de/job/systems-engineer/7194974/", "/de/job/systems-engineer/7194972/", "/de/job/senior-systems-engineer-citrix/7139368/", "/de/job/information-systems-engineer/7154423/", "/de/job/windows-systems-engineer/7179959/", "/de/job/systems-engineer-ecm/7169846/", "/de/job/systems-engineer-operations/7165522/", "/de/job/praktikant-systems-engineer-jet/7192042/", "/de/job/systems-engineer/7219016/", "/de/job/systems-engineer-client-und-mobile-management/7197563/", "/de/job/solution-architect-vmware-consultant/7141122/", "/de/job/systems-engineer-diabetes-care/7214185/", "/de/job/senior-systems-engineer-citrix/7139368/"]} ]
希望你能帮助我。
您必须与 json-object 一起工作。但不是字符串。
import json
with open(r'C:\Users\kevin\Dropbox\webcrawler\webcrawler\webcrawler\jobscout24.json') as f:
data = json.load(f)
url_parts = sum((p["datajoburltext"] for p in data), [])
print(*['https://www.jobscout24.ch' + part for part in url_parts], sep='\n')