【发布时间】:2018-06-17 12:54:05
【问题描述】:
我编写了这段代码来获取 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' 无关紧要
【问题讨论】:
-
使用循环语句
-
您应该将
res = requests.get(link)替换为res = requests.get(url)。它目前使用全局链接而不是作为参数提供的 url