Postingan lainnya
scrape dengan bs4
saya membuat script untuk scrape meowfest.com dengan beautifulsoup (bs4)
#Importing modules
import requests
from bs4 import BeautifulSoup
#cat_fest()
def cat_fest():
#headers
headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Max-Age': '3600',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36'
}
#url
url = "https://meowfest.com/"
#response
response = requests.get(url, headers)
#soup
soup = BeautifulSoup(response.content, "html.parser")
#for x
for e, x in enumerate(soup.findAll("div", class_="sqs-block-content")):
print(str("\n".join(x)))
#test
print(cat_fest())
tapi kenapa saya dapat error seperti ini
Traceback (most recent call last):
File "/Users/user/Documents/AryaUwU/Python for game/kivyGame/Game Arya/scrape_catfest/catfest.py", line 30, in <module>
print(cat_fest())
File "/Users/user/Documents/AryaUwU/Python for game/kivyGame/Game Arya/scrape_catfest/catfest.py", line 27, in cat_fest
print(str("\n".join(x)))
TypeError: sequence item 0: expected str instance, Tag found
Process finished with exit code 1
0
Tanggapan
tolong dibantu dong :(
1 Jawaban:
<div>Method .join() memerlukan argumen berupa sebuah iterable (list, tuple, dll), dimana setiap elemen dari iterable tersebut bertipe str<br>Contoh ini akan serupa dengan error di atas</div><pre>a = [5, 6, 7]
“,”.join(a) # error</pre><div>Yaitu:</div><pre>TypeError: sequence item 0: expected str instance, int found</pre><div><br>Singkatnya, pastikan terlebih dulu bahwa semua elemen di dalam list x berupa string<br>#cmiiw</div>
0
Tanggapan
Terimakasih atas jawabannya kak, :)