BS4错误“ NoneType”对象没有属性“ find_all”。无法解析HTML数据

时间:2019-08-14 13:05:44

标签: python-2.7 beautifulsoup

BS4错误“ NoneType”对象没有属性“ find_all”。无法解析html数据。

  const [productId, setProductId] = useState(null);
  const [name, setName] = useState('');
  const [description, setDescription] = useState('');

  const updateName = (e) =>{
    setName(e.target.value);
  }
  const updateDescription = (e) =>{
    setDescription(e.target.value);
  }

    onSubmit() {
        const product = {
          name: name,
          description: description
        }
        api.addProduct(product)
        .then((req, res) =>{
          setProudctId(JSON.parse(res).id);
        })
      }


return (
    <div>

        {productId && <span>Your productId: {productId} </span>} 

        <form onSubmit={addProduct}>
            <input type="text" name="name" value={name} onChange={updateName}/>
            <input type="text" name="description" value={description} onChange={updateDescription}/>
            <button>Submit</button>
        </form>
    </div>
  );
}
export default HandleProduct;

enter image description here

2 个答案:

答案 0 :(得分:0)

尝试添加headers参数:

更改:

response = session.get(endpoint)

收件人:

response = session.get(endpoint, headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'})    

答案 1 :(得分:0)

导入请求 从bs4导入BeautifulSoup作为bs

session = requests.session()

def get_sizes_in_stock():     全球会议     端点=“ https://www.sneakers76.com/en/nike/5111-nike-af1-type-ci0054-001-.html”     response = session.get(endpoint,headers = {'User-Agent':'Mozilla / 5.0(Linux; Android 6.0; Nexus 5 Build / MRA58N))AppleWebKit / 537.36(KHTML,like Gecko)Chrome / 76.0.3809.100 Mobile Safari / 537.36'})

soup = bs(response.text,"html.parser")
var = soup.find("var",{"blockwishlist_viewwishlist":"View your wishlist"})
all_sizes = var.find_all("var combinations")

sizes_in_stock = []
for size in all_sizes:
    if "0" not in size["quantity"]:
        size_id = size["attributes"]
        sizes_in_stock.append(size_id)
return sizes_in_stock

打印(get_sizes_in_stock())