【问题标题】:Scraping text data from different domain urls using Python使用 Python 从不同的域 url 中抓取文本数据
【发布时间】:2020-07-15 12:39:51
【问题描述】:

有没有办法只从 Python 中的不同域 url 中抓取文本数据?

例如,在this 网站中,文本位于与this 页面不同的块中。我想编写一个函数,允许我同时从这两个网站上抓取文本。这在 Python 中可行吗?

【问题讨论】:

  • 更精确地确定您想要做什么。分别请求两个网站并连接结果文本是一种方法,但您必须知道要从这些页面中提取什么。

标签: python web-scraping


【解决方案1】:

python 中唯一可能的事情是抓取页面的整个文本。您可以使用该代码执行此操作。

import requests
from bs4 import BeautifulSoup
r = requests.get('https://www.businessinsider.in/tech/news/airbnb-is-getting-ripped-apart-for-asking-renters-to-donate-money-to-landlords/articleshow/76968577.cms')
soup = BeautifulSoup(r.text, 'html.parser')
texet = soup.find('html').text
print(texet)

【讨论】:

    猜你喜欢
    • 2021-05-13
    • 2017-11-14
    • 2013-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-05
    • 2022-07-31
    • 1970-01-01
    相关资源
    最近更新 更多