首页 > 解决方案 > Python——网络抓取——“TypeError:‘NoneType’对象不可调用”

问题描述

python web scraping here,我试图从网站获取内容。但它显示类型错误

import urllib.request
from bs4 import BeautifulSoup


response1 = urllib.request.urlopen('https://www.flipkart.com/search?q=cycle+for+men+27.5+inch&as=on&as- show=on&otracker=AS_Query_OrganicAutoSuggest_1_14_na_na_na&otracker1=AS_Query_OrganicAutoSuggest_1_14_na_na_na&as-pos=1&as-type=HISTORY&suggestionId=cycle+for+men+27.5+inch&requestId=8684731e-89e9-4c19-9f4f- `enter code here`dd8ac2211eb1')
parsed_content1 = BeautifulSoup(response1.read(),"html.parser")
for cycle in parsed_content1.findall('a', {"class": "s1Q9rs"}):
    print(cycle.text)

标签: pythonpython-3.x

解决方案


你必须这样做:

import time
from urllib import requests
from bs4 import BeautifulSoup

url = #your url
parser = #your parser

data = requests.get(url)
time.sleep(5)
soup = BeautifulSoup(data, parser)

#then you can search what you want

推荐阅读