Парсинг поиска Google с помощью BeautifulSoupPython

Программы на Python
Anonymous
Парсинг поиска Google с помощью BeautifulSoup

Сообщение Anonymous »

Я хотел парсить несколько страниц поиска Google.
До сих пор мне удавалось парсить только первую страницу, но как я мог сделать это для нескольких страниц?

from bs4 import BeautifulSoup
import requests
import urllib.request
import re
from collections import Counter

def search(query):
url = "http://www.google.com/search?q="+query

text = []
final_text = []

source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text,"html.parser")

for desc in soup.find_all("span",{"class":"st"}):
text.append(desc.text)

for title in soup.find_all("h3",attrs={"class":"r"}):
text.append(title.text)

for string in text:
string = re.sub("[^A-Za-z ]","",string)
final_text.append(string)

count_text = ' '.join(final_text)
res = Counter(count_text.split())

keyword_Count = dict(sorted(res.items(), key=lambda x: (-x[1], x[0])))

for x,y in keyword_Count.items():
print(x ," : ",y)

search("girl")


Подробнее здесь: https://stackoverflow.com/questions/533 ... utifulsoup

Вернуться в «Python»