其实就是类型问题,强转一下就好了,加一个str()就行了
resp = requests.get(url=url,headers=head)
bs = BeautifulSoup(resp.text,'html.parser')
record = open('hello.txt','w+t',encoding='utf-8')
a = bs.find_all("a")
b = str(a)
record.write(b)
该博客展示了如何利用Python的requests库获取网页内容,然后通过BeautifulSoup解析HTML,找到所有链接元素<a>。将这些链接转换为字符串后,写入到名为'hello.txt'的文件中,以便后续分析或存储。
其实就是类型问题,强转一下就好了,加一个str()就行了
resp = requests.get(url=url,headers=head)
bs = BeautifulSoup(resp.text,'html.parser')
record = open('hello.txt','w+t',encoding='utf-8')
a = bs.find_all("a")
b = str(a)
record.write(b)
833

被折叠的 条评论
为什么被折叠?