Web scraping 如何使用python web scraping提取每个产品的标题
以下是链接:Web scraping 如何使用python web scraping提取每个产品的标题,web-scraping,python-requests,Web Scraping,Python Requests,以下是链接: 查找所有div,其中包含classnamename(class=“name”)。这会给你所有的书名。如果您想要href,请遍历所有标题,并找到一个标签,该标签具有标题是标题的文本。文本 import requests import bs4 as bs url = 'https://www.118100.se/sok/foretag/?q=brf&loc=&ob=rel&p=0' response = requests.get(url) # print('
查找所有
div
,其中包含class
namename
(class=“name”)。这会给你所有的书名。如果您想要href
,请遍历所有标题
,并找到一个标签,该标签具有标题
是标题的文本。文本
import requests
import bs4 as bs
url = 'https://www.118100.se/sok/foretag/?q=brf&loc=&ob=rel&p=0'
response = requests.get(url)
# print('Response:', response.status_code)
soup = bs.BeautifulSoup(response.text, 'lxml')
titles = soup.find_all('div', {'class': 'Name'})
# a = soup.find_all('a')
# print(a)
for title in titles:
link = soup.find('a', {'title': title.text}).get('href')
print('https://www.118100.se' + link)
您好,谢谢,但此代码仅显示“response 200”。您能修改它,使它只显示标题链接吗?求你了,先生@卡迪亚先生
import requests
import bs4 as bs
url = 'https://www.118100.se/sok/foretag/?q=brf&loc=&ob=rel&p=0'
response = requests.get(url)
# print('Response:', response.status_code)
soup = bs.BeautifulSoup(response.text, 'lxml')
titles = soup.find_all('div', {'class': 'Name'})
# a = soup.find_all('a')
# print(a)
for title in titles:
link = soup.find('a', {'title': title.text}).get('href')
print('https://www.118100.se' + link)