【发布时间】:2020-07-21 08:11:14
【问题描述】:
它没有打印出任何结果并返回一个奇怪的错误,如图所示使用pycharm。
我写的代码:
import requests
from bs4 import BeautifulSoup
def webcrawler(max_pages,url):
page = 1
if page <= max_pages:
webpage = (url) + str(page)
source_code = requests.get(url)
code_text = source_code.text
soup_format = BeautifulSoup(code_text)
for link in soup_format.findAll('a', {'class': 's-item__image-wrapper'}):
href = str(url) + link.get('href')
title = link.string
print(href)
print(title)
page += 1
webcrawler(1, 'https://www.ebay.com/b/Cell-Phone-Accessories/9394/bn_320095?_pgn=')
【问题讨论】:
-
请不要发布代码或错误的图像。见meta.stackoverflow.com/questions/285551/…
-
警告说要使用解析器
-
另外,你确定你要提取的数据不是JS加载的,并且已经存在于你的
source_code中了吗? -
您是否要提取页面中产品的所有超链接?
标签: python web-crawler