Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Web scraping 如何使用python web scraping提取每个产品的标题_Web Scraping_Python Requests - Fatal编程技术网

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
name
name
(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)