python - 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)
解决方案
你必须这样做:
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
推荐阅读
- javascript - 什么情况下会触发 axios.interceptors.request.use 错误回调函数?
- reactjs - Typescript 从服务器获取数据并加载状态
- python - 在多个文件夹上运行 Python 脚本
- c++ - 有没有办法在语句中同时使用 int 和 string
- firebase - 如何在firestore中为订单构建数据?
- python - Python分组;仅在满足条件时保留
- python-3.x - Nvidia Quadro P2000 和 Quadro K5000 与 tensorflow 2.x 版本的兼容性
- express - Axios 获取请求不会停止加载并且不会返回任何结果
- javascript - 无法使用 Next JS 进行服务器端渲染 Styled-Components
- sql - 根据一定的设定频率选择数据