小编TAN*_*-OK的帖子

在 Python 3 中使用 BeautifulSoup 抓取 URL

我尝试了这段代码,但包含 URL 的列表仍为空。没有错误按摩,什么都没有。

from bs4 import BeautifulSoup
from urllib.request import Request, urlopen
import re

req = Request('https://www.metacritic.com/browse/movies/genre/date?page=0', headers={'User-Agent': 'Mozilla/5.0'})
html_page = urlopen(req).read()

soup = BeautifulSoup(html_page, features="xml")
links = []
for link in soup.findAll('a', attrs={'href': re.compile("^https://www.metacritic.com/movie/")}):
    links.append(link.get('href'))

print(links)
Run Code Online (Sandbox Code Playgroud)

我想抓取在给定 URL“ https://www.metacritic.com/browse/movies/genre/date ? ”中找到的所有以“ https://www.metacritic.com/movie/”开头的 URL?页=0 “。

我究竟做错了什么?

python urllib beautifulsoup python-3.x

2
推荐指数
1
解决办法
7461
查看次数

将列表中的字符串设置为列表中的两个字符串

我有一个列表,如:

['Mark', 'Reynold', 'Peter', 'Randall Macenroe'] #The list is a lot longer, so I can't go by index
Run Code Online (Sandbox Code Playgroud)

我想将该列表更改为另一个列表:

['Mark', 'Reynold', 'Peter', 'Randall', 'Macenroe']
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?我肯定可以在两个名字之间使用那个空格(两个名字之间总会有空格),但是怎么样?

python split list python-2.7

1
推荐指数
1
解决办法
41
查看次数

标签 统计

python ×2

beautifulsoup ×1

list ×1

python-2.7 ×1

python-3.x ×1

split ×1

urllib ×1