import urllib.request
from bs4 import BeautifulSoup
import re
def getPrice( ebayno):
print(ebayno)
url = "http://www.ebay.com/itm/" + str(ebayno)
req = urllib.request.Request(url=url)
try:
webpage = urllib.request.urlopen(req)
except:
print("removed")
return
html = webpage.read()
soup = BeautifulSoup(html, 'html.parser')
results0 = soup.find("span", class_="pivHdr--sub-heading")
if results0 is not None:
if results0.contents[0].find("0 results.") != -1:
print("0 results.")
return
price = soup.find("span", id="prcIsum")
if price is not None:
# print(price.contents)
USprice = re.findall("\d*,?\d*,?\d+\.\d+", price.contents[0])
USprice = str(USprice[0]).replace(",", "") # 价格
print("right")
print(USprice)
return USprice
else:
price = soup.find("span", id="mm-saleDscPrc")
# print(price.contents)
USprice = re.findall("\d*,?\d*,?\d+\.\d+", price.contents[0])
USprice = str(USprice[0]).replace(",", "") # 价格
print("discout")
print(USprice)
return USprice
with open("test1.txt") as fp:
for ebayno in fp:
getPrice(ebayno.strip())
ebay价格抓取 考虑remove 0results end
最新推荐文章于 2023-11-24 18:12:44 发布