我写这个代码来获得Ebay的价格
它要求完整的ebay链接,然后它写出它的价格
import bs4 , requests
print('please enter full Ebay link ..')
link = str(input())
def ebayprice(url):
res = requests.get(link)
res.raise_for_status()
txt = bs4.BeautifulSoup(res.text , 'html.parser')
csselement = txt.select('#mm-saleDscPrc')
return csselement[0].text.strip()
price = ebayprice(link)
print('price is : '+ price)
我想改进它,我尽我所能,我无法做到
我希望它采取多个链接并逐个运行它,它应该每次都写出结果
链接是来自input()还是来自links =’www1,www2,www3’无关紧要
最佳答案 你可以用逗号分割并使用for循环遍历列表:
def ebayprice(url):
...
for single_link in link.split(','):
price = ebayprice(single_link)
print('price for {} is {}'.format(single_link, price))