我写了这段代码来获得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'
答案 0 :(得分:1)
您可以使用逗号分割并使用list
遍历for loop
:
def ebayprice(url):
...
for single_link in link.split(','):
price = ebayprice(single_link)
print('price for {} is {}'.format(single_link, price))
答案 1 :(得分:0)
如果你想要你可以询问有多少链接,有人想要抓,然后你可以使用循环语句来浏览每个网址
How many links do you want wo scrape ?
2
please enter full Ebay link ..
http://example.com
http://example-just-test.com
# simple print the url
http://example.com
http://example-just-test.com
示例:
{{1}}