【发布时间】:2021-10-20 05:42:31
【问题描述】:
所以我正在尝试根据一些俄罗斯人在 youtube 上的视频运行 BS4 ebay 刮板。我对这种编写刮板的方式很陌生,到目前为止我只使用过 selenium,但想尝试一些新的更快的东西,可以在服务器上部署一次,这样我就可以获取我刮到手机中的数据,例如当我不在家。我的目标是从我解析的 h3 对象中打印出文本,但输出会打印出以下内容:("
import requests
from bs4 import BeautifulSoup
def get_page(url):
response = requests.get(url)
if not response.ok:
print("Server responded:", response.status_code)
else:
soup = BeautifulSoup(response.text, "lxml")
return soup
def get_detail_data(soup):
listing = soup.find("div", {"class": "s-item__wrapper clearfix"})
name = soup.find_all("h3", {"class": "s-item__title"}, text=True)
print(name)
def main():
url = "https://www.ebay.de/b/Laptops-Notebooks/175672/bn_1618754?LH_ItemCondition=7000&mag=1&rt=nc&_sop=1"
get_page(url)
get_detail_data(get_page(url))
if __name__ == "__main__":
main()
【问题讨论】:
-
所以你无法获取
name?? -
哦,帖子自己重新编辑了,抱歉
标签: python python-3.x web-scraping beautifulsoup python-requests