我试图通过抓取一个网站来提取悉尼的邮政编码和郊区作为数据框
我已经在beautifulsup中找到了相应的标签,但无法完成该过程
import requests
from bs4 import BeautifulSoup
url = 'https://data.mongabay.com/igapo/australia/postcodes/sydney-numeric.html'
res = requests.get(url)
soup = BeautifulSoup(res.text,'html5lib')
table = soup.find_all('table')[10]
rows = table.find_all('td')[2]
for br in rows.find_all("br"):
br.replace_with("\n")
parsedText = rows.get_text()
我期待一个数据帧,例如:
postcode suburbs
2000 Australia Square Post Office
2000 Circular Quay
2000 Clarence Street Post Office
...
谢谢你的帮助
你几乎做了所有的工作!你只要把它读对就行了。你知道吗
所以我们需要使用StringIO使您的文本能够被
pd.read_csv
读取,然后我们可以使用一些regex来定义分隔符。你知道吗r'(?<=\d) '
如果前面有数字,则查找空格(注意“)”后面的空格)。你知道吗有点冗长的方法。bs4.7.1标准
相关问题 更多 >
编程相关推荐