the code is as follows:
from urllib.request import urlopen
from urllib.request import Request
from urllib import parse
from bs4 import BeautifulSoup as bs
import re
-sharp req = Request("http://www.baidu.com")
req = Request("https://www.csdn.net/")
req.add_header("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36")
resp = urlopen(req)
html_doc = resp.read().decode("utf-8")
-sharp html_doc = "<html><head><title></title></head><body></body></html>"
soup = bs(html_doc,"xml")
-sharp print(soup.title.string)
-sharp for link in soup.findAll("a"):
-sharp print(link.string)
**links = soup.findAll("a",href=re.compile("^(https://www.csdn.net/)")**
for link in links:
if re.search("^(_blank)$",link["target"])
print(link.get_text())
error message:
add a syntax error, please see what is wrong, online, etc.-sharp-sharp-sharp problem description
the environmental background of the problems and what methods you have tried
related codes
/ / Please paste the code text below (do not replace the code with pictures)