【发布时间】:2020-09-18 14:46:14
【问题描述】:
我正在尝试抓取一个网站,但是我无法完成代码,以便我可以一次插入多个 URL。目前,该代码一次只能使用一个 URL,
目前的代码是:
import requests
from bs4 import BeautifulSoup
import lxml
import pandas as pd
from urllib.request import urlopen
from urllib.error import HTTPError
from urllib.error import URLError
from bs4 import BeautifulSoup
try:
html = urlopen("http://google.com")
except HTTPError as e:
print(e)
except URLError:
print("error")
else:
res = BeautifulSoup(html.read(),"html5lib")
tags = res.findAll("div", {"itemtype": "http://schema.org/LocalBusiness"})
title = res.title.text
print(title)
for tag in tags:
print(tag)
有人可以帮我修改一下,以便我可以插入这样的东西吗?
html = urlopen ("url1, url2, url3")
【问题讨论】:
-
你问的没有意义。 BeautifulSoup 不是这样工作的。为什么不使用相同的代码一次处理一个 URL,如果您希望同时处理这三个 URL 会起作用? - 或者您是否期望发生比单独处理每个 URL 时更复杂的结果?
标签: python beautifulsoup html5lib