相关疑难解决方法(0)

Beautifulsoup:.find()和.select() - python 3.xx之间有区别吗?

我有一个简单的问题:

当您使用Beautiful Soup刮取网站的某个部分时,您可以使用data.find()/ data.findAll()或data.select()

现在的问题是..find().select()方法之间是否存在显着差异?(例如,在表现或灵活性方面,或......)

还是他们一样?

亲切的问候

python beautifulsoup python-3.x

26
推荐指数
1
解决办法
3万
查看次数

使用 Python 抓取谷歌搜索结果标题和网址

我正在使用 Python(3.7) 进行一个项目,在该项目中我需要抓取标题和网址的前几个 Google 结果,我已经尝试使用 BeautifulSoup 但它不起作用:

这是我尝试过的:

import requests
from my_fake_useragent import UserAgent
from bs4 import BeautifulSoup

ua = UserAgent()

google_url = "https://www.google.com/search?q=python" + "&num=" + str(5)
response = requests.get(google_url, {"User-Agent": ua.random})
soup = BeautifulSoup(response.text, "html.parser")

result_div = soup.find_all('div', attrs={'class': 'g'})

links = []
titles = []
descriptions = []
for r in result_div:
    # Checks if each element is present, else, raise exception
    try:
        link = r.find('a', href=True)
        title = r.find('h3', attrs={'class': 'r'}).get_text()
        description = r.find('span', attrs={'class': 'st'}).get_text() …
Run Code Online (Sandbox Code Playgroud)

html python beautifulsoup web-scraping python-beautifultable

3
推荐指数
1
解决办法
4474
查看次数