【发布时间】:2017-12-13 18:30:34
【问题描述】:
我正在尝试编写一个机器人来将商品添加到我的购物车然后为我购买,因为我需要进行非常定期的购买,而自己购买它们变得乏味。
from bs4 import BeautifulSoup
import requests
import numpy as np
page = requests.get("http://www.onlinestore.com/shop")
soup = BeautifulSoup(page.content, 'html.parser')
try:
for i in soup.find_all('a'):
if "shop" in i['href']:
shop_page = requests.get("http://www.onlinestore.com" + i['href'])
item_page = BeautifulSoup(shop_page.content, 'html.parser')
for h in item_page.find_all('form', class_="add"):
print(h['action'])
try:
shop_page = requests.get("http://www.online.com" + h['action'])
except:
print("None left")
for h in item_page.find_all('h1', class_="protect"):
print(h.getText())
except:
print("either ended or error occured")
checkout_page = requests.get("http://www.onlinestore.com/checkout")
checkout = BeautifulSoup(checkout_page.content, 'html.parser')
for j in checkout.find_all('strong', id_="total"):
print(j)
我在检查产品时遇到了一些麻烦,因为这些物品没有结转。有没有一种方法可以实现 cookie,以便跟踪我添加到购物车的商品?
谢谢
【问题讨论】:
标签: python-3.x session beautifulsoup screen-scraping